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

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

rennokki/rating
===============

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

3.1.0(4y ago)19016.9k25[3 PRs](https://github.com/renoki-co/rating/pulls)Apache-2.0PHPCI passing

Since Jul 23Pushed 3mo ago4 watchersCompare

[ Source](https://github.com/renoki-co/rating)[ Packagist](https://packagist.org/packages/rennokki/rating)[ Docs](https://github.com/renoki-co/rating)[ GitHub Sponsors](https://github.com/rennokki)[ RSS](/packages/rennokki-rating/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (21)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

50

—

FairBetter than 95% of packages

Maintenance55

Moderate activity, may be stable

Popularity41

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 78.7% 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 ~86 days

Recently: every ~111 days

Total

16

Last Release

1551d ago

Major Versions

1.1.0 → 2.0.02019-11-23

2.4.1 → 3.0.02021-04-17

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/21983456?v=4)[rennokki](/maintainers/rennokki)[@rennokki](https://github.com/rennokki)

---

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)")[![semsphy](https://avatars.githubusercontent.com/u/423396?v=4)](https://github.com/semsphy "semsphy (1 commits)")

---

Tags

assign-ratingseloquentlaravelmodelphpratinglaravelmodeleloquentsystemRatestarsRatingstar

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[cybercog/laravel-love

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

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

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[qirolab/laravel-reactions

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

19564.6k](/packages/qirolab-laravel-reactions)

PHPackages © 2026

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