Skip to content

Commit

Permalink
Add sumRating methods to fetch rating when using +1/-1 style ratings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Vincent committed Aug 27, 2015
1 parent 7707a30 commit ee24365
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Rateable/Rateable.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ public function averageRating()
->pluck('averageRating');
}

public function sumRating()
{
return $this->ratings()
->selectRaw('SUM(rating) as sumRating')
->pluck('sumRating');
}

public function ratingPercent($max = 5)
{
$ratings = $this->ratings();
Expand All @@ -31,4 +38,10 @@ public function getAverageRatingAttribute()
{
return $this->averageRating();
}

public function getSumRatingAttribute()
{
return $this->sumRating();
}

}

0 comments on commit ee24365

Please sign in to comment.