PHPackages                             centrex/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. centrex/laravel-ratings

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

centrex/laravel-ratings
=======================

Add rating to any model in laravel

v2.0.0(6mo ago)02.1k[4 PRs](https://github.com/centrex/laravel-ratings/pulls)MITPHPPHP ^8.2|^8.3|^8.4CI passing

Since Dec 2Pushed 1mo agoCompare

[ Source](https://github.com/centrex/laravel-ratings)[ Packagist](https://packagist.org/packages/centrex/laravel-ratings)[ Docs](https://github.com/centrex/laravel-ratings)[ RSS](/packages/centrex-laravel-ratings/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (15)Versions (15)Used By (0)

Add rating to any model in laravel
==================================

[](#add-rating-to-any-model-in-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0cbd8b4d17141aa9dd23a5cbcd2453086f0d336bd51f9d8d7055e9b9c2e03920/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63656e747265782f726174696e67732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/centrex/ratings)[![GitHub Tests Action Status](https://camo.githubusercontent.com/9d04228d8281534d1b1a6c1321ad347c1f78bf5dfd6f0fd25d986984bfead1eb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f63656e747265782f726174696e67732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/centrex/ratings/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/d8dd9866ae8f131ee050dbf7fd0532e541c50dd694febe5deddc8c59c326fc33/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f63656e747265782f726174696e67732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/centrex/ratings/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/608444f8f8b021c878cd932a0b55cde855016e7ec6ffafa753b2da894b950d79/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f63656e747265782f726174696e67733f7374796c653d666c61742d737175617265)](https://packagist.org/packages/centrex/ratings)

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.

Contents
--------

[](#contents)

- [Installation](#installation)
- [Usage Examples](#usage)
- [Testing](#testing)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)

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

[](#installation)

You can install the package via composer:

```
composer require centrex/ratings
```

You can publish the config file with:

```
php artisan vendor:publish --tag="ratings-config"
```

This is the contents of the published config file:

```
return [
    'users' => [
        'table' => 'users',
        'primary_key' => 'user_id',
    ],

    'max_rating' => 5,

    'undo_rating' => true,
];
```

Usage
-----

[](#usage)

Add a `InterectsWithRating` trait to the Model you want to be ratable.

```
use Centrex\Ratings\Concerns\InterectsWithRating;

class Product extends Model
{
    use InterectsWithRating;

    // ...
}
```

Now you can rate any Model.

**Rate the Model**

```
$product = Product::find(1);
```

```
$product->rate(4);
```

or

```
$product->rate(score: 2);
```

**View Models' ratings**

```
$product->ratings;
```

You can get an overall percentage of the amount of Users' who have rated a Model:

Imagine you want a five-star rating system, and you have a Model that has been rated a `3` and a `5` by two Users'

```
$product->ratingPercent(maxLength: 5);
```

This will equate to 80%. A float is returned. Changing the `maxLength` will recalculate the percentage.

You could then use this percentage for the `score` attribute of the component.

> **Note**
>
> By default, the `maxLength` is determined by a config option. You can override this by passing a value to the method.

**Unrating Models**

By default, you can unrate a Model. If you don't want Users' to unrate Models, set the `undo_rating` config option to true.

To unrate a Model, you can use the `unrate` method:

```
$product->unrate();
```

The package comes with a bunch of Attributes that you can use. *The results of these are based off a single Model been rated by two Users' with a `3` and ` 5` rating.*

```
$product->averageRating; // "4.0000"
$product->averageRatingByUser; // "5.0000"
$product->averageSumOfUser; // 5
$product->ratedByUsers; // 2
$product->ratedInTotal; // 2
$product->sumRating; // "8"
```

### Livewire Component

[](#livewire-component)

To see the ratings in action, you can use the Livewire component. This allows you to show the ratings on the front-end statically and let the User's rate the Model by clicking on the stars.

> **Warning**
>
> You must have both Tailwind CSS and Font Awesome installed, though Font Awesome can be replaced with your own preferred icon set

**Use the component**

```

```

The component has customisable attributes, including:

```
public string $iconBgColor = 'text-yellow-300';
public string $iconFgColor = 'text-yellow-400';
public float $score = 0;
public string $size = 'text-base';
public bool $static = false;
```

If you have the config for unrating a Model set to `true`, an icon shows that allows you to unrate the Model.

Testing
-------

[](#testing)

🧹 Keep a modern codebase with **Pint**:

```
composer lint
```

✅ Run refactors using **Rector**

```
composer refacto
```

⚗️ Run static analysis using **PHPStan**:

```
composer test:types
```

✅ Run unit tests using **PEST**

```
composer test:unit
```

🚀 Run the entire test suite:

```
composer test
```

Changelog
---------

[](#changelog)

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

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

[](#contributing)

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

Credits
-------

[](#credits)

- [centrex](https://github.com/centrex)
- [All Contributors](../../contributors)
- [cjmellor/rating](https://github.com/cjmellor/rating)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance79

Regular maintenance activity

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 62% 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 ~77 days

Recently: every ~121 days

Total

10

Last Release

202d ago

Major Versions

v1.3.0 → v2.0.02025-10-29

PHP version history (4 changes)v1.0.0PHP ^8.0|^8.1

v1.0.3PHP ^8.1|^8.2

v1.2.0PHP ^8.1|^8.2|^8.3

v1.3.0PHP ^8.2|^8.3|^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/3b62fd49922fd1bf7d55b94cc82ebc9f359af7f343b246a7e3a2642779c0b4e7?d=identicon)[rochi88](/maintainers/rochi88)

---

Top Contributors

[![rochi88](https://avatars.githubusercontent.com/u/29769944?v=4)](https://github.com/rochi88 "rochi88 (31 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (11 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 commits)")

---

Tags

laravelratingscentrex

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[glhd/special

1929.4k](/packages/glhd-special)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

116.6k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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