'int', 'author_id' => 'int', 'views_count' => 'int', 'published_at' => 'datetime', 'keywords' => 'array', 'metadata' => 'object', ]; protected $fillable = [ 'serp_url_id', 'title', 'slug', 'main_keyword', 'keywords', 'bites', 'author_id', 'featured_image', 'body', 'views_count', 'status', 'published_at', 'metadata', 'society_impact', 'society_impact_level', 'image_ref_url', ]; protected function featuredImage(): Attribute { return Attribute::make( get: function ($value = null) { if (! is_empty($value)) { return Storage::disk('r2')->url($value); } return null; } ); } protected function getFeaturedThumbImageAttribute() { $value = $this->featured_image; //dd($value); if (! is_empty($value)) { // Extract the file extension $extension = pathinfo($value, PATHINFO_EXTENSION); // Construct the thumbnail filename by appending '_thumb' before the extension $thumbnail = str_replace(".{$extension}", "_thumb.{$extension}", $value); return $thumbnail; // Return the full URL to the thumbnail image //return Storage::disk('r2')->url($thumbnail); } return null; } public function serp_url() { return $this->belongsTo(SerpUrl::class); } public function author() { return $this->belongsTo(Author::class); } public function post_categories() { return $this->hasMany(PostCategory::class); } public function post_entities() { return $this->hasMany(PostEntity::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 entities() { return $this->hasManyThrough( Entity::class, // The target model PostEntity::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 (PostEntity) 'entity_id' // The foreign key on the target model (Entity) ); } public function toFeedItem(): FeedItem { return FeedItem::create([ 'id' => $this->id, 'title' => $this->title, 'summary' => $this->bites, 'updated' => $this->updated_at, 'link' => route('front.post', ['slug' => $this->slug, 'category_slug' => $this->category->slug]), 'authorName' => 'FutureWalker', ]); } public static function getFeedItems() { return self::with('category')->where('status', 'publish')->latest('published_at')->take(20)->get(); } }