'datetime', 'tags' => 'array', 'is_featured' => 'boolean', 'allow_comments' => 'boolean', 'view_count' => 'integer', ]; public function author() { return $this->belongsTo(User::class, 'author_id'); } public function careerApplication() { return $this->belongsTo(CareerApplication::class, 'career_application_id'); } public function category() { return $this->belongsTo(BlogCategory::class, 'category_id'); } public function comments() { return $this->hasMany(BlogComment::class); } // Route key için id kullan (Filament için gerekli) // public function getRouteKeyName() // { // return 'slug'; // } public function getUrlAttribute() { return '/blog/' . $this->slug; } public function getAuthorNameAttribute() { if ($this->author) { return $this->author->name; } if ($this->careerApplication) { return $this->careerApplication->name; } return __('blog.default_author'); } public function getAuthorRoleAttribute() { if ($this->author && $this->author->role) { return $this->author->role; } if ($this->careerApplication) { return 'Stajyer Yazılım Geliştirici'; } return 'Trunçgil Teknoloji Editörü'; } public function getAuthorAvatarUrlAttribute() { if ($this->author && $this->author->avatar) { return asset('storage/' . $this->author->avatar); } return asset('assets/img/avatars/u5.webp'); } public function getFeaturedImageUrlAttribute() { if ($this->featured_image) { return asset('storage/' . $this->featured_image); } return null; } public function getReadingTimeAttribute() { $wordCount = str_word_count(strip_tags($this->content)); $minutesToRead = round($wordCount / 200); // Ortalama 200 kelime/dakika return max(1, $minutesToRead); } public function scopePublished($query) { return $query->where('status', 'published') ->where(function($q) { $q->whereNull('published_at') ->orWhere('published_at', '<=', now()); }); } public function scopeFeatured($query) { return $query->where('is_featured', true); } public function scopeByCategory($query, $categoryId) { return $query->where('category_id', $categoryId); } public function scopeByTag($query, $tag) { return $query->whereJsonContains('tags', $tag); } }