Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with the implementation #37

Open
dev-humayun opened this issue Jun 23, 2022 · 9 comments
Open

Help with the implementation #37

dev-humayun opened this issue Jun 23, 2022 · 9 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@dev-humayun
Copy link

Can we get the average rating of all the Posts
like

Post::averageRating(2)
@codebyray
Copy link
Owner

codebyray commented Aug 17, 2022

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

@codebyray codebyray added the question Further information is requested label Aug 17, 2022
@dev-humayun
Copy link
Author

yes exactly

@codebyray codebyray added the enhancement New feature or request label Aug 18, 2022
@codebyray
Copy link
Owner

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.

@H4ck3r-x0
Copy link

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
Copy link

@dev-humayun did you work around this issue?

@codebyray
Copy link
Owner

codebyray commented Feb 14, 2023

@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
Copy link
Author

@dev-humayun did you work around this issue?

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

@H4ck3r-x0
Copy link

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants