laravel-review-rateable
laravel-review-rateable copied to clipboard
Help with the implementation
Can we get the average rating of all the Posts like
Post::averageRating(2)
@dev-humayun Do you mean you want to get the average rating for every post in the table?
yes exactly
I will work on this and tray and get it into the next release. In the meantime, if anyone has implemented it and wants to make a pull request it would be greatly appreciated.
Hello there, thanks for the package. I am trying to get all ratings for user model by doing this
->when(request()->rating, function ($query, $rating) {
dd($query->averageRating($rating));
})
but no luck.
@dev-humayun did you work around this issue?
@H4ck3r-x0 You can get all the ratings for a user by doing something like:
$user = User::find(1);
$ratings = $user->getRecentUserRatings($user->id);
You can also just call it like this:
use Codebyray\ReviewRateable\Models\Rating;
$rating = new Rating;
// Find a user
$user = User::find(1);
$ratings = $rating->getRecentUserRatings($user->id);
You can limit the number of ratings returned as well as get approved or not approved.
/**
* @param $id - Users ID
* @param $limit
* @param $approved
* @param $sort
*/
public function getRecentUserRatings($id, $limit = 5, $approved = true, $sort = 'desc');
@dev-humayun did you work around this issue?
@H4ck3r-x0 yes i worked on it and get all the rating Sorry couldnot respond earlier
@codebyray Thanks for your reply, what I want is I have a list of users and have a filter, so i want to filter the users by their ratings
@dev-humayun Can tell me how did you do it?