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

ActiveLibrary

digikraaft/laravel-review-rating
================================

Review &amp; Rating system for Laravel

v3.2.0(8mo ago)6346.5k—8.6%9[1 PRs](https://github.com/digikraaft/laravel-review-rating/pulls)MITPHPPHP ^8.2CI failing

Since Aug 1Pushed 8mo ago2 watchersCompare

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

READMEChangelog (10)Dependencies (4)Versions (12)Used By (0)

Add Review and Rating Feature to your Laravel application
=========================================================

[](#add-review-and-rating-feature-to-your-laravel-application)

[![tests](https://github.com/digikraaft/laravel-review-rating/workflows/tests/badge.svg?branch=master)](https://github.com/digikraaft/laravel-review-rating/workflows/tests/badge.svg?branch=master)[![Build Status](https://camo.githubusercontent.com/15d5746950509ecd8415236f77b22f8a2dc742d04423402c5bde6236f040f1e5/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f646967696b72616166742f6c61726176656c2d7265766965772d726174696e672f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/digikraaft/laravel-model-suspension/build-status/master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/fcc415fa34f0a6bf7cf68962f253f560bb9234cfe88f3e2679cb03eda8dbc371/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f646967696b72616166742f6c61726176656c2d7265766965772d726174696e672f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/digikraaft/laravel-model-suspension/?branch=master)[![Code Intelligence Status](https://camo.githubusercontent.com/1b052014512a97cf86c1befbc2575bb5607ae92557be02441fd46cdf505f3b39/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f646967696b72616166742f6c61726176656c2d7265766965772d726174696e672f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d6173746572)](https://scrutinizer-ci.com/code-intelligence)[![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](https://opensource.org/licenses/MIT)

Review and Rating System for Laravel
------------------------------------

[](#review-and-rating-system-for-laravel)

This package provides a simple review and rating system for Laravel. It supports Laravel 5.8 an up. Here is a quick demonstration of how it can be used:

```
//create a review
$author = User::find(1);
$review = "Awesome package! I highly recommend it!!";

$model->review($review, $author);

//write a review and include a rating
$model->review($review, $author, 5);

//write a review and include a rating and a title
$model->review($review, $author, 5, "Lovely packages");

//get the last review
$model->latestReview(); //returns an instance of \Digikraaft\ReviewRating\Review

//get the review content of the last review
$model->latestReview()->review; //returns 'Awesome package! I highly recommend it!!'

//get the rating of the last review
$model->latestReview()->rating; //return 5

//get the title of the last review
$model->latestReview()->title; //returns 'Lovely packages'
```

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

[](#installation)

You can install the package via composer:

```
composer require digikraaft/laravel-review-rating
```

You must publish the migration with:

```
php artisan vendor:publish --provider="Digikraaft\ReviewRating\ReviewRatingServiceProvider" --tag="migrations"
```

Run the migration to publish the `reviews` table with:

```
php artisan migrate
```

You can optionally publish the config-file with:

```
php artisan vendor:publish --provider="Digikraaft\ReviewRating\ReviewRatingServiceProvider" --tag="config"
```

The content of the file that will be published to `config/review-rating.php`:

```
return [
    /*
      * The class name of the review model that holds all reviews.
      *
      * The model must be or extend `Digikraaft\ReviewRating\Review`.
      */
    'review_model' => Digikraaft\ReviewRating\Models\Review::class,

    /*
     * The name of the column which holds the ID of the model related to the reviews.
     *
     * Only change this value if you have set a different name in the migration for the reviews table.
     */
    'model_primary_key_attribute' => 'model_id',

];
```

Usage
-----

[](#usage)

Add the `HasReviewRating` trait to the model:

```
use Digikraaft\ReviewRating\Traits\HasReviewRating;
use Illuminate\Database\Eloquent\Model;

class EloquentModel extends Model
{
    use HasReviewRating;
}
```

### Create a review

[](#create-a-review)

To create a review, use the `review` function of the trait. Like this:

```
$author = User::find(1);
$review = "Awesome package! I highly recommend it!!";

$model->review($review, $author);
```

The first argument is the content of the review while the second argument is the author. This can be any Eloquent model.

To create a review with rating, pass in the rating value as the third argument of the `review` function. Valid values are `int`s and `float`s:

```
$author = User::find(1);
$review = "Awesome package! I highly recommend it!!";

$model->review($review, $author, 5);
```

To create a review with rating and title, add the title as the fourth argument of the `review` function:

```
$author = User::find(1);
$review = "Awesome package! I highly recommend it!!";

$model->review($review, $author, 5, "Lovely packages");
```

You can also check if user has reviewed the model by using the `hasReviewed` function:

```
    if ($model->hasReviewed(auth()->user())) {
        // user has reviewed the model
    }
```

### Retrieving reviews

[](#retrieving-reviews)

You can get the last review like this:

```
$model->latestReview(); //returns the latest instance of Digikraaft\ReviewRating\Review
```

The content of the review can be gotten like this:

```
$model->latestReview()->review;
```

To get the rating for the review, do this:

```
$model->latestReview()->rating;
```

To get the title of the review:

```
$model->latestReview()->title;
```

All reviews can be retrieved like this:

```
$model->reviews;
```

To access each review from the reviews retrieved, do this:

```
$reviews = $model->reviews;

foreach($reviews as $review){
    echo $review->review . "";
}
```

The `allReviews` scope can be used to retrieve all the reviews for all instances of a model:

```
$allReviews = EloquentModel::allReviews();
```

### Retrieving basic Review Stats

[](#retrieving-basic-review-stats)

You can get the number of reviews a model has:

```
$model->numberOfReviews();
```

To get the number of reviews a model has received over a period, pass in a `Carbon` formatted `$from` and `$to` dates as the first and second arguments respectively:

```
//get the number of reviews a model has received over the last month
$from = now()->subMonth();
$to = now();

$model->numberOfReviews($from, $to);
```

Note that an `InvalidDate` exception will be thrown if the `$from` date is later than the `$to`

You can get the number of ratings a model has:

```
$model->numberOfRatings();
```

To get the number of ratings a model has received over a period, pass in a `Carbon` formatted `$from` and `$to` dates as the first and second arguments respectively:

```
//get the number of reviews a model has received over the last month
$from = now()->subMonth();
$to = now();

$model->numberOfRatings($from, $to);
```

To get the average rating a model has received:

```
$model->averageRating();
```

The average rating that is returned is by default not rounded. If you would like to `round` the returned result, pass an integer value of the decimal place you want it rounded to.

```
//round up to 2 decimal places
$model->averageRating(2);
```

To get the average rating a model has received over a period, pass in a `Carbon` formatted `$from` and `$to` dates as the first and second arguments respectively:

```
//get the average rating a model has received over the last month, rounded to 2 decimal places:
$from = now()->subMonth();
$to = now();

$model->averageRating(2, $from, $to);
```

The `withRatings` scope can be used to retrieve all the reviews that have a rating for all instances of a model:

```
$allReviewsWithRating = EloquentModel::withRatings();
```

### Check if model has review

[](#check-if-model-has-review)

You can check if a model has at least one review:

```
$model->hasReview();
```

### Check if model has rating

[](#check-if-model-has-rating)

You can check if a model has at least one rating:

```
$model->hasRating();
```

### Events

[](#events)

The `Digikraaft\ReviewRating\Events\ReviewCreatedEvent` event will be dispatched when a review has been created. You can listen to this event and take necessary actions. An instance of the review will be passed to the event class and can be accessed for use:

```
namespace Digikraaft\ReviewRating\Events;

use Digikraaft\ReviewRating\Models\Review;
use Illuminate\Database\Eloquent\Model;

class ReviewCreatedEvent
{
    /** @var \Digikraaft\ReviewRating\Models\Review */
    public Review $review;

    public function __construct(Review $review)
    {
        $this->review = $review;
    }
}
```

### Custom model and migration

[](#custom-model-and-migration)

You can change the model used by specifying a different class name in the `review_model` key of the `review-rating` config file.

You can also change the column name used in the `reviews` table (default is `model_id`) when using a custom migration. If this is the case, also change the `model_primary_key_attribute` key of the `review-rating` config file.

Testing
-------

[](#testing)

Use the command below to run your tests:

```
composer test
```

More Good Stuff
---------------

[](#more-good-stuff)

Check [here](https://github.com/digikraaft) for more awesome free stuff!

Changelog
---------

[](#changelog)

Please see [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.

Credits
-------

[](#credits)

- [Tim Oladoyinbo](https://github.com/timoladoyinbo)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

53

—

FairBetter than 97% of packages

Maintenance60

Regular maintenance activity

Popularity44

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 64.3% 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 ~206 days

Recently: every ~325 days

Total

10

Last Release

256d ago

Major Versions

v1.0.0 → v2.0.02020-10-20

v2.3.1 → v3.0.02023-03-04

PHP version history (6 changes)v1.0.0PHP ^7.4

v2.1.0PHP ^7.4|8.0.\*

v2.2.0PHP ^7.4|^8.0

v2.3.0PHP ^7.4|^8.0.2

v3.0.0PHP ^8.1

v3.2.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/298ea582e7fdad689b46e4fa771f3eb5caa963a9a7a76b2416dd98bada23d15f?d=identicon)[digikraaft](/maintainers/digikraaft)

---

Top Contributors

[![timoladoyinbo](https://avatars.githubusercontent.com/u/66416657?v=4)](https://github.com/timoladoyinbo "timoladoyinbo (18 commits)")[![dsbilling](https://avatars.githubusercontent.com/u/9788214?v=4)](https://github.com/dsbilling "dsbilling (8 commits)")[![faisuc](https://avatars.githubusercontent.com/u/7190009?v=4)](https://github.com/faisuc "faisuc (1 commits)")[![kwidoo](https://avatars.githubusercontent.com/u/14920653?v=4)](https://github.com/kwidoo "kwidoo (1 commits)")

---

Tags

digikraaftlaravelphpratingsreviewslaravelreviewsratingsdigikraaft

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11120.2M21](/packages/anourvalar-eloquent-serialize)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)

PHPackages © 2026

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