PHPackages                             dorvidas/laravel-ratings - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dorvidas/laravel-ratings

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dorvidas/laravel-ratings
========================

Laravel package for rating users, posts or other models with ease. You can even give a rating to a user for their role on other models i.e., post author or post illustrator.

v1.2.3(8y ago)3137MITPHPPHP &gt;=7.0

Since Jan 3Pushed 8y ago2 watchersCompare

[ Source](https://github.com/dorvidas/laravel-ratings)[ Packagist](https://packagist.org/packages/dorvidas/laravel-ratings)[ RSS](/packages/dorvidas-laravel-ratings/feed)WikiDiscussions master Synced yesterday

READMEChangelog (5)Dependencies (3)Versions (7)Used By (0)

Laravel ratings
===============

[](#laravel-ratings)

Rate users, posts or other models with ease. You can even give a rating to a user for their role on other models i.e., post author or post illustator.

- [Installation](#installation)
    - [Lumen](#lumen)
    - [Laravel](#laravel)
- [Usage](#usage)
    - [Giving a rating](#giving-a-rating)
    - [Getting a ratings of model](#getting-a-ratings)
    - [Getting ratings aggregates](#getting-rating-aggregates)
- [Config](#config)

Installation
------------

[](#installation)

- [Laravel](#test)
- [Lumen](#lumen)

### Lumen

[](#lumen)

You can install this package via composer using this command:

```
composer require dorvidas/laravel-ratings
```

Include service provider and config into `bootstrap/app.php`:

```
$app->register(\Dorvidas\Ratings\RatingsServiceProvider::class);
$app->configure('ratings');
```

### Laravel

[](#laravel)

You can install this package via composer using this command:

```
composer require dorvidas/laravel-ratings
```

Add service provider:

```
Dorvidas\Ratings\RatingsServiceProvider::class,
```

Publish vendor files:

```
php artisan vendor:publish --tag=public --force
```

Usage
-----

[](#usage)

### Giving a rating

[](#giving-a-rating)

In order to rate a model you need to access \[`RatingBuilder`\](#API of rating builder) instance. This can be done in several ways:

- By newing up instance manually:

```
    $builder = new \Dorvidas\Ratings\RatingBuilder;
    $builder->model($model)->give(5);
```

- Via facade

```
    Rate::model($model)->give(5);
```

- Via `\Dorvidas\Ratings\RateableTrait` trait method:

```
    $post->rate()->give(5);
```

#### API of rating builder

[](#api-of-rating-builder)

- `model($model)` - set what you will give rating for. When using via trait this can be ommited, because we already know the model we will rate.
- `give(5)` - set the rating. The return value is `\Dorvidas\Ratings\Models\Rating` model.
- `by($user)` - set who is rating model. If skipped authorised user is used.
- `on($model)` - this is used to define what a user is rated for. Speaking in Laravel terminology we define on which model we rate a user. Below example of rating a user for post:

```
$post = Post::first();
$user = User::first();
$user->rate()->on($post)->give(5);
```

- `as($role)` - this is used to define what was a role of a user. Speaking in Laravel terminology we define which model's column holds the user ID. If omitted it is expected that the column is `user_id`. An real life example could be giving different ratings for post author and illustrator:

```
$author = User::first();
$illustrator = User::skip(1)->first();
$author->rate()->on($post)->as('author_id')->give(5);
$illustrator()->rate()->on($post)->as('illustrator_id')->give(5);
```

### Getting a ratings

[](#getting-a-ratings)

Ratings are retrieved via `\Dorvidas\Ratings\Rating` model. Model ratings can be retrieved by querying `ratings` relations on a model. Relations is polymorphic. Don't forget to add `\Dorvidas\Ratings\MOdels\RateableTrait` for it to work.

#### Rating model fields:

[](#rating-model-fields)

- `model` - name of the rated model.
- `model_id` - ID of rated model.
- `on_model` - this is usually used when we rate a User and want to define what for (on which model) we rate him i.e., on "Post".
- `on_model_id` - ID of the model we rate model. If we rate use on "Post" this would be post ID.
- `on_model_column` - when rating using on model, with this we define what column defines user id. By default this is `user_id`.
- `rated_by` - ID of the user who rated.
- `rating` - actual rating.

#### Rating model query scopes:

[](#rating-model-query-scopes)

- `of` - filter ratings of a model. It filter by `model` and `model_id` columns.
- `on` - filter ratings on specific model. It filter by `on_model` and `on_model_id` columns.
- `as` - filter ratings by role. It filter by `on_model_column` column.
- `model` - filter by `model` column.
- `modelId` - filter by `model_id` column.
- `onModel` - filter by model `on_model` column.
- `onModelId` - filter by `on_model_id` column.

#### Examples

[](#examples)

An basic exampe of getting rating list of a "Post":

```
$post = Post::first();
$ratings = Rating::of($post)->get();
```

If there is no model object, you can pass model ID and model type via scopes `modelId` and `model`:

```
$postId = 1;
$ratings = Rating::model(Post::class)->modelId($modelId)->get();

//Or doing where statements
$ratings = Rating::where('model', Post::class)->where('model_id, $postId)->get();
```

If we want to get ratings of a user on specific model:

```
$user = User::first();
$post = Post::first();
$user->ratings()->on($post)->first(); //Returns Rating model instance
$user->ratings()->on($post)->first()->rating; //Returns actual rating
```

If we want to get ratings of a user on specific model for a specific role:

```
$user = User::first();
$post = Post::first();
$user->ratings()->on($post)->as('author_id')->first();
```

### Getting rating aggregates

[](#getting-rating-aggregates)

Rating aggregates are stored in table `rating_aggregates`. If class is using trait `RateableTrait` you can get aggregates by querying polymorphic relationship:

```
$model->rating_aggregates;
```

Whenever a rating is created an `\Dorvidas\Ratings\Events\RatingCreatedEvent` event is thrown. There is also a listener `\Dorvidas\Ratings\Listeners\RecalculateRatingAggregatesListener` which updates aggregate entry. So don't forget to register those events and listener.

Config
------

[](#config)

- `database_prefix` - allows to add database prefix.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity62

Established project with proven stability

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~6 days

Recently: every ~0 days

Total

6

Last Release

3021d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/61196e3395ce51576cd0bdfefca7c63ef2d4f763ddb441b414324c3eeb6f0e66?d=identicon)[dorvidas](/maintainers/dorvidas)

---

Tags

laravelRateRatingvoterateablefivestar

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dorvidas-laravel-ratings/health.svg)

```
[![Health](https://phpackages.com/badges/dorvidas-laravel-ratings/health.svg)](https://phpackages.com/packages/dorvidas-laravel-ratings)
```

###  Alternatives

[willvincent/laravel-rateable

Allows multiple models to be rated with a fivestar like system.

416452.0k3](/packages/willvincent-laravel-rateable)[codebyray/laravel-review-rateable

Review &amp; Rating system for Laravel 10, 11 &amp; 12

310351.9k](/packages/codebyray-laravel-review-rateable)[nikaia/nova-rating-field

Add start rating field to Laravel Nova

42258.6k](/packages/nikaia-nova-rating-field)[ghanem/rating

Rating system for Laravel

8615.5k](/packages/ghanem-rating)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
