laravel-review-rateable icon indicating copy to clipboard operation
laravel-review-rateable copied to clipboard

Help with the implementation

Open dev-humayun opened this issue 2 years ago • 9 comments

Can we get the average rating of all the Posts like

Post::averageRating(2)

dev-humayun avatar Jun 23 '22 12:06 dev-humayun

@dev-humayun Do you mean you want to get the average rating for every post in the table?

codebyray avatar Aug 17 '22 23:08 codebyray

yes exactly

dev-humayun avatar Aug 18 '22 13:08 dev-humayun

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.

codebyray avatar Aug 18 '22 21:08 codebyray

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.

H4ck3r-x0 avatar Feb 09 '23 03:02 H4ck3r-x0

@dev-humayun did you work around this issue?

H4ck3r-x0 avatar Feb 13 '23 14:02 H4ck3r-x0

@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');

codebyray avatar Feb 14 '23 03:02 codebyray

@dev-humayun did you work around this issue?

@H4ck3r-x0 yes i worked on it and get all the rating Sorry couldnot respond earlier

dev-humayun avatar Feb 14 '23 06:02 dev-humayun

@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

H4ck3r-x0 avatar Feb 19 '23 18:02 H4ck3r-x0

@dev-humayun Can tell me how did you do it?

H4ck3r-x0 avatar Feb 19 '23 18:02 H4ck3r-x0