Skip to content

Commit

Permalink
Update Reviewable.php
Browse files Browse the repository at this point in the history
  • Loading branch information
frknasir authored May 9, 2024
1 parent 27327cb commit 456b676
Showing 1 changed file with 0 additions and 46 deletions.
46 changes: 0 additions & 46 deletions src/Reviewable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace StarfolkSoftware\Gauge;

use Illuminate\Database\Eloquent\Casts\Attribute;

trait Reviewable
{
/**
Expand Down Expand Up @@ -43,48 +41,4 @@ public function reviews()
{
return $this->morphMany(Gauge::$reviewModel, 'reviewable');
}

/**
* Returns the latest review.
*/
public function latestReview(): Attribute
{
return Attribute::make(fn () => $this->reviews()->latest()->first());
}

/**
* Calculates the avarage rating
*/
public function averageRating(): Attribute
{
return Attribute::make(fn () => $this->reviews()->avg('rating'));
}

/**
* Calculates the total value of ratings
*/
public function totalRating(): Attribute
{
return Attribute::make(fn () => $this->reviews()->sum('rating'));
}

/**
* Returns the reviews count
*
* @return \Illuminate\Database\Eloquent\Casts\Attribute
*/
public function reviewsCount()
{
return Attribute::make(fn () => $this->reviews()->count());
}

/**
* Returns the count of the users that have rated.
*
* @return \Illuminate\Database\Eloquent\Casts\Attribute
*/
public function usersCount()
{
return Attribute::make(fn () => $this->reviews()->groupBy('user_id')->pluck('user_id')->count());
}
}

0 comments on commit 456b676

Please sign in to comment.