Ratings: Ratings that add up on any model
Ratings lets any Eloquent model rate any other, once per rater, with a value on the scale you choose and an optional comment. One call creates or updates the rating and tells you which, and the average, count and distribution of a model's ratings come straight from the database.
Everything a rating system needs
Two traits and one migration, with the rules enforced for you.
One Rating Per Rater
A unique index keeps each rater and model to one rating, even under simultaneous requests.
Created, Updated, or Unchanged
rate() returns a RatingResult with the status and the value before and after.
Optional Comments
Omit the comment to keep it, pass a string to replace it, or null to clear it.
Exact Scales
One to five by default, or any range and step per model, such as 0 to 10 in half steps.
SQL Aggregates
averageRating(), ratingsCount(), ratingDistribution() and whereRatingAtLeast(), without loading ratings.
Any Model, Any Key
Integer, UUID and ULID keys, morph maps, soft deletes and native Eloquent relations.
A quick look
Rate, read, and summarize in a few lines.
1$result = $user->rate($product, 4, 'Nice product'); 2$result->created(); // true 3 4$result = $user->rate($product, 5); // keeps the comment 5$result->previous(); // 4 6 7$user->ratingFor($product)->update(['comment' => 'Even better']); 8 9$product->averageRating(); // 5.010$product->ratingDistribution(); // [5 => 1]11Product::whereRatingAtLeast(4)->paginate();Ratings Questions
Quick answers about installing and using Ratings.
What is Ratings?
Let any Eloquent model rate any other, once per rater, with a value on an exact scale and an optional comment: rate() creates or updates and reports which, and averages, counts and distributions come straight from SQL. It's a free, open-source Laravel package by Pharaonic.
How do I install Ratings?
Run composer require pharaonic/laravel-ratings in your project's root directory, then php artisan migrate.
What does Ratings require?
The latest release requires PHP 8.3+ and Laravel 13.
Can a user rate the same model twice?
No. Each rater has one rating per model; rating again updates it, and rate() tells you whether it was created, updated, or unchanged.
Can I use half stars or a 0 to 10 scale?
Yes. Set the default min, max and step in the configuration, or define ratingScale() on a model to give it its own scale. Values may have up to 4 decimal places.
How do I change a rating's comment only?
Get the rating with ratingFor() and call update(['comment' => '...']) on it, like any Eloquent model.
Is Ratings free to use?
Yes. Ratings is open source under the MIT license, so you can use it in personal and commercial projects.
Where can I find the Ratings documentation?
Read the Ratings documentation for setup, configuration, and usage examples.
How do I report a bug or contribute to Ratings?
Open an issue or a pull request on GitHub, ask in GitHub Discussions, or chat with us on Discord.
Ready to dig in?
Read the full documentation for installation, configuration, comments, rating scales, aggregates and queries, events, soft deletes, and concurrency.