morphMany(Rating::class, 'rateable'); } public function getAverageRatingAttribute() { return round($this->ratings()->avg('stars'), 1); } public function getUserRatingAttribute() { if (!auth()->check()) return null; return $this->ratings() ->where('user_id', auth()->id()) ->value('stars'); } public function getRatingsCountAttribute() { return $this->ratings()->count(); } }