PHPackages                             compubel/laravel-rating - 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. [Database &amp; ORM](/categories/database)
4. /
5. compubel/laravel-rating

ActiveLibrary[Database &amp; ORM](/categories/database)

compubel/laravel-rating
=======================

Associate ratings to any Eloquent model

1.3.0(4y ago)13521[1 PRs](https://github.com/compubel/laravel-rating/pulls)MITPHPPHP ^7.2|^8.0

Since Mar 9Pushed 4y ago1 watchersCompare

[ Source](https://github.com/compubel/laravel-rating)[ Packagist](https://packagist.org/packages/compubel/laravel-rating)[ Docs](https://github.com/compubel/laravel-rating)[ RSS](/packages/compubel-laravel-rating/feed)WikiDiscussions master Synced 2mo ago

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

Laravel Rating
==============

[](#laravel-rating)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4413c89dec33bad7d061c696b2be13afb00f55f11e744ca53db0583d6aeaa8e3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f6d707562656c2f6c61726176656c2d726174696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/compubel/laravel-rating)[![Build Status](https://camo.githubusercontent.com/883c219f9d09241b4710fbc3f40331ff9f2593251177d2816262a7741b706dfb/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f6d707562656c2f6c61726176656c2d726174696e672f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/compubel/laravel-rating)[![codecov](https://camo.githubusercontent.com/91a1eb71d17a7d8aa30ce287be254833c7c4bd9e92cf598b6bc3f813d44e90fd/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f636f6d707562656c2f6c61726176656c2d726174696e672e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/compubel/laravel-rating)[![Quality Score](https://camo.githubusercontent.com/6ce614438794032e43cd4c66cd26b5392b1cb3a558812b6ae37e3c2a62d6886e/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f636f6d707562656c2f6c61726176656c2d726174696e672e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/compubel/laravel-rating)[![StyleCI](https://camo.githubusercontent.com/251c2a89fc522fa3241a509229f2611d635c51f0ca9cf0a2eaedb936cfbf3263/68747470733a2f2f7374796c6563692e696f2f7265706f732f3137343735313434322f736869656c64)](https://styleci.io/repos/174751442)[![Total Downloads](https://camo.githubusercontent.com/1a1c99e0d65fcde7da5b3e7e1aed8fbb4c5cb72c25cd3ab890f25f9b15dce3cc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f6d707562656c2f6c61726176656c2d726174696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/compubel/laravel-rating)

Associate ratings to any Eloquent model.

This package is based on [rennokki/rating](https://github.com/rennokki/rating) with some improvements:

- Bugfixes
- Exceptions
- Sum of ratings
- More testing

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

[](#installation)

Install this package with Composer:

```
$ composer require compubel/laravel-rating
```

The package will automatically register itself.

If your Laravel installation does not support package discovery, add this line in the providers array in your config/app.php file:

```
Compubel\Rating\RatingServiceProvider::class,
```

Optional: if you want to change the table name to something else than "ratings", you can publish the config file with:

```
php artisan vendor:publish --provider="Compubel\Rating\RatingServiceProvider" --tag="config"
```

Publish the migration with:

```
php artisan vendor:publish --provider="Compubel\Rating\RatingServiceProvider" --tag="migrations"
```

After the migration has been published you can create the ratings table by running the migration:

```
php artisan migrate
```

Usage
-----

[](#usage)

### Prepare models

[](#prepare-models)

To allow a model to rate other models, it should use the `CanRate` trait and implement the `Rater` contract.

```
use Compubel\Rating\CanRate;
use Compubel\Rating\Contracts\Rater;

class User extends Model implements Rater
{
    use CanRate;

    // ...
}
```

Each model that can be rated, should use the `CanBeRated` trait and implement the `Rateable` contract.

```
use Compubel\Rating\CanBeRated;
use Compubel\Rating\Contracts\Rateable;

class Post extends Model implements Rateable
{
    use CanBeRated;

    // ...
}
```

If your model can both rate and be rated, you should use `Rate` trait and `Rating` contract.

```
use Compubel\Rating\Rate;
use Compubel\Rating\Contracts\Rating;

class Member extends Model implements Rating
{
    use Rate;

    // ...
}
```

### Rate models

[](#rate-models)

To rate other models, simply call `rate()` method. As a second argument to the `rate()` method, you can pass the rating score. It can either be string, integer or float.

```
$user->rate($post, 10);
$post->averageRating(User::class); // 10.0, as float
```

If you want to make sure a model gets rated only once, add `false` as the third argument to the `rate()` method.

```
$user->rate($post, 10, false);
```

Check if a model has been rated with the `hasRated()` method.

```
$user->rate($post, 10);
$user->hasRated($post); // true
```

Get the average rating of a model with the `averageRating()` method. Pass the class name of the raters as the argument. The return value is the average arithmetic value of all ratings as `float`.

```
$user->rate($post, 10);
$post->averageRating(User::class); // 10.0, as float
```

Get the ratings count with the `countRatings()` method.

```
$user->rate($post, 10);
$user->rate($post, 10);
$post->countRatings(User::class); // 2, as integer
```

Testing
-------

[](#testing)

You can run the tests with:

```
$ composer test
```

Changelog
---------

[](#changelog)

Please see the [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Alternatives
------------

[](#alternatives)

- [rennoki/rating](https://github.com/rennokki/rating)
- [willvincent/laravel-rateable](https://github.com/willvincent/laravel-rateable)
- [AbdullahGhanem/rating](https://github.com/AbdullahGhanem/rating)

Credits
-------

[](#credits)

- [Jasper Briers](https://github.com/compubel)
- [All Contributors](../../contributors)

License
-------

[](#license)

MIT. Please see the [license file](LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~174 days

Recently: every ~218 days

Total

6

Last Release

1748d ago

PHP version history (2 changes)1.1.1PHP ^7.2

1.2.0PHP ^7.2|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/b6b5689d96a92aab8916255e0eee754c9beacec4674cdce6676deef7c1957ca6?d=identicon)[CasperBE](/maintainers/CasperBE)

---

Top Contributors

[![CasperBE](https://avatars.githubusercontent.com/u/22048227?v=4)](https://github.com/CasperBE "CasperBE (19 commits)")

---

Tags

laravelphpratingratingslaravelRatinglaravel-rating

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/compubel-laravel-rating/health.svg)

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

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[qirolab/laravel-reactions

Implement reactions (like, dislike, love, emotion etc) on Laravel Eloquent models.

19564.6k](/packages/qirolab-laravel-reactions)[rennokki/rating

Laravel Eloquent Rating allows you to assign ratings to any model.

19016.9k](/packages/rennokki-rating)

PHPackages © 2026

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