This commit is contained in:
2026-05-20 15:42:10 +03:30
parent 6f5224a5d9
commit 02448db346
2 changed files with 2 additions and 33 deletions
-31
View File
@@ -45,37 +45,6 @@ public function tags(): BelongsToMany
protected $appends = ['url', 'image_url' , 'average_rating', 'user_rating', 'comments_count'];
// New rating and comment relationships
public function ratings(): MorphMany
{
return $this->morphMany(Rating::class, 'rateable');
}
public function comments(): MorphMany
{
return $this->morphMany(Comment::class, 'commentable');
}
// Accessors for ratings
public function getAverageRatingAttribute(): float
{
return round($this->ratings()->avg('stars'), 1);
}
public function getUserRatingAttribute(): ?int
{
if (!auth()->check()) return null;
return $this->ratings()
->where('user_id', auth()->id())
->value('stars');
}
public function getCommentsCountAttribute(): int
{
return $this->comments()->count();
}
// Accessor for full URL
public function getUrlAttribute()
{
return asset('storage/' . $this->file_path);