'int', 'featured' => 'bool', 'views_count' => 'int', 'keywords' => 'array', 'published_at' => 'datetime', ]; protected $fillable = [ 'title', 'short_title', 'slug', 'type', 'excerpt', 'author_id', 'featured', 'featured_image', 'body', 'views_count', 'status', 'main_keyword', 'keywords', 'published_at', ]; public function getFeaturedImageLqipCdnAttribute() { if (! is_empty($this->featured_image)) { // Get the extension of the original featured image $extension = pathinfo($this->featured_image, PATHINFO_EXTENSION); // Append "_lqip" before the extension to create the LQIP image URL $lqipFeaturedImage = str_replace(".{$extension}", '_lqip.webp', $this->featured_image); return 'https://'.Storage::disk('r2')->url($lqipFeaturedImage).'?a=bc'; } return null; } public function getFeaturedImageCdnAttribute() { if (! is_empty($this->featured_image)) { return 'https://'.Storage::disk('r2')->url($this->featured_image); } return null; } public function author() { return $this->belongsTo(Author::class); } public function category() { return $this->hasOneThrough( Category::class, // The target model PostCategory::class, // The through model 'post_id', // The foreign key on the through model 'id', // The local key on the parent model (Post) 'id', // The local key on the through model (PostCategory) 'category_id' // The foreign key on the target model (Category) ); } public function toFeedItem(): FeedItem { return FeedItem::create([ 'id' => $this->id, 'title' => $this->title, 'summary' => $this->excerpt, 'updated' => $this->updated_at, 'link' => route('posts.show', $this->slug), 'authorName' => optional($this->author)->name, ]); } public static function getFeedItems() { return self::where('status', 'published')->latest('published_at')->take(10)->get(); } }