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

ActiveLibrary

subashkhanal37/laravel-review-rating
====================================

Review &amp; Rating system for Laravel 12|11|10

v1.0.0(1y ago)1433↓100%MITPHPPHP ^8.1CI passing

Since Mar 19Pushed 1y ago1 watchersCompare

[ Source](https://github.com/SubashKhanal37/laravel-review-rating)[ Packagist](https://packagist.org/packages/subashkhanal37/laravel-review-rating)[ Docs](https://github.com/subashkhanal37/laravel-review-rating)[ RSS](/packages/subashkhanal37-laravel-review-rating/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (4)Versions (2)Used By (0)

This is the fork of digikraaft / laravel-review-rating

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

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

[![tests](https://github.com/subashkhanal37/laravel-review-rating/workflows/tests/badge.svg?branch=main)](https://github.com/subashkhanal37/laravel-review-rating/workflows/tests/badge.svg?branch=main)[![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 10 and 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 \subashkhanal37\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 subash/laravel-review-rating
```

You must publish the migration with:

```
php artisan vendor:publish --provider="subashkhanal37\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="subashkhanal37\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 `subashkhanal37\ReviewRating\Models\Review`.
      */
    'review_model' => subashkhanal37\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 subashkhanal37\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 subashkhanal37\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 `subashkhanal37\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 subashkhanal37\ReviewRating\Events;

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

class ReviewCreatedEvent
{
    /** @var \subashkhanal37\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/Subash) 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)

- [Subash Khanal](https://github.com/subashkhanal37)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

31

—

LowBetter than 71% of packages

Maintenance49

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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

Unknown

Total

1

Last Release

368d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/15a1d5bde712553f35ecdf27f60e249f83eaeb468fa6c50cc62b70da905f0d83?d=identicon)[SubashKhanal37](/maintainers/SubashKhanal37)

---

Top Contributors

[![SubashKhanal37](https://avatars.githubusercontent.com/u/93086312?v=4)](https://github.com/SubashKhanal37 "SubashKhanal37 (9 commits)")

---

Tags

laravelreviewsratingssubash

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[digikraaft/laravel-review-rating

Review &amp; Rating system for Laravel

6244.3k](/packages/digikraaft-laravel-review-rating)[ondrakoupil/heureka-recenze

Knihovna pro snadný import recenzí e-shopu a produktů z Heuréka.cz

1091.4k](/packages/ondrakoupil-heureka-recenze)

PHPackages © 2026

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