Skip to content

Commit

Permalink
added count rating
Browse files Browse the repository at this point in the history
  • Loading branch information
Trexology committed Dec 5, 2015
1 parent eb09629 commit 127736f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ or
$post->averageRating(2) //round to 2 decimal place
````

### Count total rating:
````php
$post->countRating()
````

### Fetch the rating percentage.
This is also how you enforce a maximum rating value.
````php
Expand Down
6 changes: 6 additions & 0 deletions src/Contracts/ReviewRateable.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public function ratings();
*/
public function averageRating($round= null);

/**
*
* @return mix
*/
public function countRating();

/**
*
* @return mix
Expand Down
10 changes: 10 additions & 0 deletions src/Traits/ReviewRateable.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ public function averageRating($round= null)
->pluck('averageReviewRateable');
}

/**
*
* @return mix
*/
public function countRating(){
return $this->ratings()
->selectRaw('count(rating) as countReviewRateable')
->pluck('countReviewRateable');
}

/**
*
* @return mix
Expand Down

0 comments on commit 127736f

Please sign in to comment.