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

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

canylmz/laravel-rating
======================

Associate ratings to any Eloquent model

v0.0.2(6y ago)06MITPHPPHP ^7.2CI failing

Since Oct 19Pushed 6y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (6)Versions (3)Used By (0)

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

[](#laravel-rating)

[![Latest Version on Packagist](https://camo.githubusercontent.com/12c80e70c052d5dabe286531a139389ef5ac973b0d873fad16225a65a6935141/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63616e796c6d7a2f6c61726176656c2d726174696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/canylmz/laravel-rating)[![Latest Stable Version](https://camo.githubusercontent.com/46a8e200e35ab00844ecfbfda5b7f469d22d6551a69b03b9e04c6cfff63219d2/68747470733a2f2f706f7365722e707567782e6f72672f63616e796c6d7a2f6c61726176656c2d726174696e672f762f737461626c65)](https://packagist.org/packages/canylmz/laravel-rating)[![Build Status](https://camo.githubusercontent.com/f10cdc8e747c085edbe1de18d971d498af095676bebdeb7d4aaa1ea78c46199c/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f63616e796c6d7a2f6c61726176656c2d726174696e672f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/canylmz/laravel-rating)[![codecov](https://camo.githubusercontent.com/0b78a660d110b916e5c1437894f485ed44d904997e12616b991df1cf0f3dcf44/68747470733a2f2f636f6465636f762e696f2f67682f63616e796c6d7a2f6c61726176656c2d726174696e672f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/canylmz/laravel-rating)[![Quality Score](https://camo.githubusercontent.com/d919c55110a665423a1050fd54009ec9753a8d4c723a29b3094080e319a38cf3/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f63616e796c6d7a2f6c61726176656c2d726174696e672e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/canylmz/laravel-rating)[![StyleCI](https://camo.githubusercontent.com/d2baf26865972eb5f7e2980e27b18ab5688d9374be6d0fc4aef46ede8037c5f4/68747470733a2f2f7374796c6563692e696f2f7265706f732f3231363235333437362f736869656c64)](https://styleci.io/repos/216253476)[![Total Downloads](https://camo.githubusercontent.com/5c02172dfe9e93e376848461bcf438b7bd1dd9f4be2adfc61701573591d5942a/68747470733a2f2f706f7365722e707567782e6f72672f63616e796c6d7a2f6c61726176656c2d726174696e672f646f776e6c6f616473)](https://packagist.org/packages/canylmz/laravel-rating)[![License](https://camo.githubusercontent.com/e50d023676843080ea3af1ffb194ebf8a9b8cd7bf34de075913ccf9db9b9b3e9/68747470733a2f2f706f7365722e707567782e6f72672f63616e796c6d7a2f6c61726176656c2d726174696e672f6c6963656e7365)](https://packagist.org/packages/canylmz/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 canylmz/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:

```
Canylmz\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="Canylmz\Rating\RatingServiceProvider" --tag="config"
```

Publish the migration with:

```
php artisan vendor:publish --provider="Canylmz\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 Canylmz\Rating\CanRate;
use Canylmz\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 Canylmz\Rating\CanBeRated;
use Canylmz\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 Canylmz\Rating\Rate;
use Canylmz\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.

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)

- [Can YILMAZ](https://github.com/canylmz)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

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

Total

2

Last Release

2397d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/29094296?v=4)[Can Yılmaz](/maintainers/canylmz)[@canylmz](https://github.com/canylmz)

---

Top Contributors

[![canylmz](https://avatars.githubusercontent.com/u/29094296?v=4)](https://github.com/canylmz "canylmz (8 commits)")

---

Tags

laravelmodeleloquentsystemRatestarsRatingstarlaravel-rating

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[rennokki/rating

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

19016.9k](/packages/rennokki-rating)[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)[qirolab/laravel-reactions

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

19564.6k](/packages/qirolab-laravel-reactions)[dyrynda/laravel-model-uuid

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

4802.8M8](/packages/dyrynda-laravel-model-uuid)

PHPackages © 2026

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