feat: user rating and comment

This commit is contained in:
2026-05-20 15:52:28 +03:30
parent 02448db346
commit d0d48866f0
7 changed files with 171 additions and 19 deletions
+25
View File
@@ -24,9 +24,34 @@ public function getUserRatingAttribute()
->where('user_id', auth()->id())
->value('stars');
}
// Get user's rating object
public function userRating()
{
if (!auth()->check()) return null;
return $this->ratings()
->where('user_id', auth()->id())
->first();
}
// Check if user has rated
public function getHasUserRatedAttribute()
{
return !is_null($this->userRating());
}
public function getRatingsCountAttribute()
{
return $this->ratings()->count();
}
// Get rating distribution
public function getRatingDistributionAttribute()
{
$distribution = [];
for ($i = 1; $i <= 5; $i++) {
$distribution[$i] = $this->ratings()->where('stars', $i)->count();
}
return $distribution;
}
}