|
12 | 12 | use App\Traits\HasTags;
|
13 | 13 | use App\Traits\Reactable;
|
14 | 14 | use App\Traits\RecordsActivity;
|
| 15 | +use Carbon\Carbon; |
15 | 16 | use CyrildeWit\EloquentViewable\Contracts\Viewable;
|
16 | 17 | use CyrildeWit\EloquentViewable\InteractsWithViews;
|
17 | 18 | use Illuminate\Database\Eloquent\Factories\HasFactory;
|
18 | 19 | use Illuminate\Database\Eloquent\Model;
|
19 | 20 | use Illuminate\Support\Str;
|
20 | 21 | use Spatie\MediaLibrary\HasMedia;
|
21 | 22 | use Spatie\MediaLibrary\InteractsWithMedia;
|
| 23 | +use Spatie\Sitemap\Contracts\Sitemapable; |
| 24 | +use Spatie\Sitemap\Tags\Url; |
22 | 25 |
|
23 | 26 | /**
|
24 | 27 | * @property-read int $id
|
|
33 | 36 | * @property int $user_id
|
34 | 37 | * @property string | null $locale
|
35 | 38 | * @property-read User $user
|
36 |
| - * @property \Carbon\Carbon | null $published_at |
37 |
| - * @property \Carbon\Carbon | null $submitted_at |
38 |
| - * @property \Carbon\Carbon | null $approved_at |
39 |
| - * @property \Carbon\Carbon | null $shared_at |
40 |
| - * @property \Carbon\Carbon | null $declined_at |
41 |
| - * @property \Carbon\Carbon | null $sponsored_at |
42 |
| - * @property \Carbon\Carbon $created_at |
43 |
| - * @property \Carbon\Carbon $updated_at |
| 39 | + * @property Carbon | null $published_at |
| 40 | + * @property Carbon | null $submitted_at |
| 41 | + * @property Carbon | null $approved_at |
| 42 | + * @property Carbon | null $shared_at |
| 43 | + * @property Carbon | null $declined_at |
| 44 | + * @property Carbon | null $sponsored_at |
| 45 | + * @property Carbon $created_at |
| 46 | + * @property Carbon $updated_at |
44 | 47 | * @property \Illuminate\Database\Eloquent\Collection | Tag[] $tags
|
45 | 48 | */
|
46 |
| -final class Article extends Model implements HasMedia, ReactableInterface, Viewable |
| 49 | +final class Article extends Model implements HasMedia, ReactableInterface, Sitemapable, Viewable |
47 | 50 | {
|
48 | 51 | use HasAuthor;
|
49 | 52 | use HasFactory;
|
@@ -96,6 +99,14 @@ public function newEloquentBuilder($query): ArticleQueryBuilder
|
96 | 99 | return new ArticleQueryBuilder($query);
|
97 | 100 | }
|
98 | 101 |
|
| 102 | + public function toSitemapTag(): Url |
| 103 | + { |
| 104 | + return Url::create(route('articles.show', $this)) |
| 105 | + ->setLastModificationDate(Carbon::create($this->updated_at)) // @phpstan-ignore-line |
| 106 | + ->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY) |
| 107 | + ->setPriority(0.5); |
| 108 | + } |
| 109 | + |
99 | 110 | public function excerpt(int $limit = 110): string
|
100 | 111 | {
|
101 | 112 | return Str::limit(strip_tags((string) md_to_html($this->body)), $limit);
|
|
0 commit comments