PHPackages                             leomachado94/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. leomachado94/rating

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

leomachado94/rating
===================

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

054PHP

Since Jun 23Pushed 3y agoCompare

[ Source](https://github.com/LeoMachado94/rating)[ Packagist](https://packagist.org/packages/leomachado94/rating)[ RSS](/packages/leomachado94-rating/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

Laravel Eloquent Rating
=======================

[](#laravel-eloquent-rating)

[![CI](https://github.com/renoki-co/rating/workflows/CI/badge.svg?branch=master)](https://github.com/renoki-co/rating/workflows/CI/badge.svg?branch=master)[![codecov](https://camo.githubusercontent.com/d3dcd8e1d8d6fa67035864e8cd706639b5a18a875bb86f6a1aaffd7985f35a77/68747470733a2f2f636f6465636f762e696f2f67682f72656e6f6b692d636f2f726174696e672f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/renoki-co/rating/branch/master)[![StyleCI](https://camo.githubusercontent.com/3d449bf0e1d2493d2eff87e76f9d2416a8cf64c920cd90258783d9cf48603d10/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3134323034393730312f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/141194551)[![Latest Stable Version](https://camo.githubusercontent.com/6e29ae9186df8a7de96529555a5e48bf7f9189e4a1620a866ebaf51c73ce9c49/68747470733a2f2f706f7365722e707567782e6f72672f72656e6e6f6b6b692f726174696e672f762f737461626c65)](https://packagist.org/packages/rennokki/rating)[![Total Downloads](https://camo.githubusercontent.com/93f9cae6a85c7bdf3ee6b05db6e3c43a644cdff52b3a111e52b24301588096f6/68747470733a2f2f706f7365722e707567782e6f72672f72656e6e6f6b6b692f726174696e672f646f776e6c6f616473)](https://packagist.org/packages/rennokki/rating)[![Monthly Downloads](https://camo.githubusercontent.com/95c7d1cf00f994d52a1ad5721374922cfa5823e6a5951eeeb914ca50e7039b58/68747470733a2f2f706f7365722e707567782e6f72672f72656e6e6f6b6b692f726174696e672f642f6d6f6e74686c79)](https://packagist.org/packages/rennokki/rating)[![License](https://camo.githubusercontent.com/f1e758e5d47e1023c66816736c99cac4d93c2798c98261d8fb9a592464c9e62a/68747470733a2f2f706f7365722e707567782e6f72672f72656e6e6f6b6b692f726174696e672f6c6963656e7365)](https://packagist.org/packages/rennokki/rating)

Laravel Eloquent Rating allows you to assign ratings to any model, just like any other review based on stars.

🤝 Supporting
------------

[](#-supporting)

**If you are using one or more Renoki Co. open-source packages in your production apps, in presentation demos, hobby projects, school projects or so, sponsor our work with [Github Sponsors](https://github.com/sponsors/rennokki). 📦**

[![](https://camo.githubusercontent.com/9c9f61bbf0edbcba5341bf892ba73fc37167c46c8365905f8a8991b319920dae/68747470733a2f2f6769746875622d636f6e74656e742e73332e66722d7061722e7363772e636c6f75642f7374617469632f32322e6a7067)](https://github-content.renoki.org/github-repo/22)

🚀 Installation
--------------

[](#-installation)

Install the package:

```
$ composer require rennokki/rating
```

Publish the config:

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

Publish the migrations:

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

Preparing the model
-------------------

[](#preparing-the-model)

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

```
use Rennokki\Rating\Traits\CanRate;
use Rennokki\Rating\Contracts\Rater;

class User extends Model implements Rater
{
    use CanRate;
    ...
}
```

The other models that can be rated should use `CanBeRated` trait and `Rateable` contract.

```
use Rennokki\Rating\Traits\CanBeRated;
use Rennokki\Rating\Contracts\Rateable;

class User extends Model implements Rateable
{
    use CanBeRated;
    ...
}
```

If your model can both rate &amp; be rated by other models, you should use `Rate` trait and `Rating` contract.

```
use Rennokki\Rating\Traits\Rate;
use Rennokki\Rating\Contracts\Rating;

class User extends Model implements Rating
{
    use Rate;

    //
}
```

🙌 Usage
-------

[](#-usage)

To rate other models, simply call `rate()` method:

```
$page = Page::find(1);

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

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

To update a rating, you can call `updateRatingFor()` method:

```
$user->updateRatingFor($page, 9);
$page->averageRating(User::class); // 9.00, as float
```

As you have seen, you can call `averageRating()` within models that can be rated. The return value is the average arithmetic value of all ratings as `float`.

If we leave the argument empty, we will get `0.00` because no other `Page` model has rated the page so far. But since users have rated the page, we will calculate the average only from the `User` models, since only they have voted the page, strictly by passing the class name as the argument.

```
$page = Page::find(1);

$user1->rate($page, 10);
$user2->rate($page, 6);

$page->averageRating(); // 0.00
$page->averageRating(User::class); // 8.00, as float
```

While in our example, the `User` class can both rate and be rated, we can leave the argument empty if we reference to its class:

```
$user = User::find(1);

$user1->rate($user, 10);
$user2->rate($user, 6);

$user->averageRating(); // 8.00, as float
$user->averageRating(User::class); // 8.00, it is equivalent
```

The relationships are based on this too:

```
$page->raters()->get(); // Pages that have rated this page
$page->raters(User::class)->get(); // Users that have rated this page

$user->ratings()->get(); // Users that this user has rated
$user->ratings(Page::class)->get(); // Pages that this user has rated
```

🐛 Testing
---------

[](#-testing)

```
vendor/bin/phpunit
```

🤝 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.

🎉 Credits
---------

[](#-credits)

- [Alex Renoki](https://github.com/rennokki)
- [All Contributors](../../contributors)

###  Health Score

16

—

LowBetter than 4% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity24

Early-stage or recently created project

 Bus Factor1

Top contributor holds 78.2% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/9c1cd21811de15960ef09179d0cbfca1bcb24fd1b6087f0ed9c47ac506efbce9?d=identicon)[LeoMachado94](/maintainers/LeoMachado94)

---

Top Contributors

[![rennokki](https://avatars.githubusercontent.com/u/21983456?v=4)](https://github.com/rennokki "rennokki (111 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (23 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (5 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (1 commits)")[![LeoMachado94](https://avatars.githubusercontent.com/u/11590935?v=4)](https://github.com/LeoMachado94 "LeoMachado94 (1 commits)")[![semsphy](https://avatars.githubusercontent.com/u/423396?v=4)](https://github.com/semsphy "semsphy (1 commits)")

### Embed Badge

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

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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