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

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

fajarwz/laravel-review
======================

Flexible and powerful review system for Laravel, let any model review and be reviewed.

1.2.0(1y ago)26192MITPHP

Since Aug 13Pushed 1y ago4 watchersCompare

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

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

Laravel Review
==============

[](#laravel-review)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3691c4e087a0714193a0071ccd075abb9c3fe3ffb3c84cb3c000faaace2ab813/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f66616a6172777a2f6c61726176656c2d7265766965772e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/fajarwz/laravel-review)[![GitHub Tests Action Status](https://github.com/fajarwz/laravel-review/actions/workflows/run-tests.yml/badge.svg)](https://github.com/fajarwz/laravel-review/actions/workflows/run-tests.yml)[![GitHub Code Style Action Status](https://github.com/fajarwz/laravel-review/actions/workflows/fix-php-code-style-issues.yml/badge.svg)](https://github.com/fajarwz/laravel-review/actions/workflows/fix-php-code-style-issues.yml)

[![](https://camo.githubusercontent.com/3a6a608c32480138b4bc16190949dd78e92173735f49f9226259d675701f907d/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c2532305265766965772e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d66616a6172777a2532466c61726176656c2d726576696577267061747465726e3d617263686974656374267374796c653d7374796c655f32266465736372697074696f6e3d466c657869626c652b616e642b706f77657266756c2b7265766965772b73797374656d2b666f722b4c61726176656c2532432b6c65742b616e792b6d6f64656c2b7265766965772b616e642b62652b72657669657765642e266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)](https://camo.githubusercontent.com/3a6a608c32480138b4bc16190949dd78e92173735f49f9226259d675701f907d/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c2532305265766965772e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d66616a6172777a2532466c61726176656c2d726576696577267061747465726e3d617263686974656374267374796c653d7374796c655f32266465736372697074696f6e3d466c657869626c652b616e642b706f77657266756c2b7265766965772b73797374656d2b666f722b4c61726176656c2532432b6c65742b616e792b6d6f64656c2b7265766965772b616e642b62652b72657669657765642e266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)

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

[](#installation)

You can install the package via composer:

```
composer require fajarwz/laravel-review
```

You can publish and run the migrations with:

```
php artisan vendor:publish --provider="Fajarwz\LaravelReview\LaravelReviewServiceProvider"
php artisan migrate
```

Setup
-----

[](#setup)

### Models Setup

[](#models-setup)

Include the necessary traits in your models:

#### Reviewed/Reviewable Model

[](#reviewedreviewable-model)

For models that can be reviewed, use the `CanBeReviewed` trait:

```
use Fajarwz\LaravelReview\Traits\CanBeReviewed;

class Mentor extends Model
{
    use CanBeReviewed;
    // Optionally, use CanReview if the model can also act as a reviewer
    // use CanReview;
}
```

#### Reviewer Model

[](#reviewer-model)

For models that can submit reviews, use the `CanReview` trait:

```
use Fajarwz\LaravelReview\Traits\CanReview;

class Mentee extends Model
{
    use CanReview;
}
```

Usage
-----

[](#usage)

### Creating a Review

[](#creating-a-review)

To create a new review:

```
$mentee = Mentee::find(1);
$mentor = Mentor::find(1);

// Create an approved review
$mentee->review($mentor, 4.5);

// Create an unapproved review
$mentee->review($mentor, 3.0, 'Needs improvement', false);
```

The `review()` method takes a reviewable model and a rating. Optionally, set the review content to add a review and set the `$isApproved` parameter to `false` to create an unapproved review.

Only approved reviews are calculated in the `review_summaries` table. Updating an unapproved review will not affect the summary.

If the reviewer model has already submitted a review for the same reviewable model, a `Fajarwz\LaravelReview\Exceptions\DuplicateReviewException` will be thrown.

To update a review, use `updateReview()` instead.

### Updating a review

[](#updating-a-review)

To update an existing review:

```
$mentee->updateReview($mentor, 5, 'Mentor is even better now!');
```

The `updateReview()` method accepts three parameters: a reviewable model, a rating, and an optional review text.

### Unreviewing a model

[](#unreviewing-a-model)

To cancel an existing review:

```
$mentee->unreview($mentor);
```

If the reviewer model has not previously reviewed the model, a `Fajarwz\LaravelReview\Exceptions\ReviewNotFoundException` will be thrown.

### Approving a Review

[](#approving-a-review)

To approve a review:

```
$review = $mentor->receivedReviews()->first();
$review->approve();
```

### Unapproving a Review

[](#unapproving-a-review)

To unapprove a review:

```
$review = $mentor->receivedReviews()->first();
$review->unapprove();
```

### Querying Reviews

[](#querying-reviews)

#### Get all received reviews

[](#get-all-received-reviews)

By default, only approved reviews are retrieved:

```
$mentor->receivedReviews()->get();
```

To get the latest received reviews:

```
$mentor->latestReceivedReviews()->paginate();
```

To get the top-rated received reviews:

```
$mentor->topRatedReceivedReviews()->paginate();
```

To include both approved and unapproved reviews:

```
$mentor->receivedReviews()->withUnapproved()->get();
```

To include reviewer information:

```
Mentor::with('receivedReviews.reviewer')->paginate();
```

This query will eager load the reviewer information for each received review.

**Note:** Consider using appropriate eager loading strategies based on your application's needs to optimize query performance.

#### Get a review received from a specified reviewer

[](#get-a-review-received-from-a-specified-reviewer)

To retrieve a review that a reviewer has given to reviewable:

```
$review = $mentor->getReceivedReview($mentee);
```

This method returns a single `Review` instance or `null` if no review exists.

To include unapproved reviews in the search, pass `true` as the second parameter:

```
$includeUnapproved = true;
$review = $mentor->getReceivedReview($mentee, $includeUnapproved);
```

#### Get all given reviews

[](#get-all-given-reviews)

To get all reviews given by a model:

```
$mentee->givenReviews()->get();
```

To include reviewable model information:

```
Mentee::with('givenReviews.reviewable')->paginate();
```

This will eager load the reviewable model for each review given by the model.

#### Get a review given from a specified reviewable model

[](#get-a-review-given-from-a-specified-reviewable-model)

To retrieve a given review that a reviewable has received from reviewer:

```
$review = $mentee->getGivenReview($mentor);
```

This method returns a single `Review` instance or `null` if no review exists.

To include unapproved reviews in the search, pass `true` as the second parameter:

```
$includeUnapproved = true;
$review = $mentor->getGivenReview($mentee, $includeUnapproved);
```

### Checking for Reviews

[](#checking-for-reviews)

#### Check if a reviewable model has received a review from a specific reviewer

[](#check-if-a-reviewable-model-has-received-a-review-from-a-specific-reviewer)

```
if ($mentor->hasReceivedReview($mentee)) {
    // The mentor has received a review from the mentee
}
```

To include unapproved reviews in the check, pass `true` as the second parameter:

```
$includeUnapproved = true;
if ($mentor->hasReceivedReview($mentee, $includeUnapproved)) {
    // The mentor has received a review from the mentee
}
```

#### Check if the current model has given a review to the specified model

[](#check-if-the-current-model-has-given-a-review-to-the-specified-model)

```
if ($mentee->hasGivenReview($mentor)) {
    // The mentee has given a review to the mentor
}
```

To include unapproved reviews in the check, pass `true` as the second parameter:

```
$includeUnapproved = true;
if ($mentee->hasGivenReview($mentor, $includeUnapproved)) {
    // The mentee has given a review to the mentor
}
```

### Review Model

[](#review-model)

The `Fajarwz\LaravelReview\Models\Review` model includes methods for managing and querying reviews:

#### Approve a Review

[](#approve-a-review)

To approve a review, use the `approve()` method. This sets the `approved_at` timestamp to the current date and time, indicating that the review has been approved. It also updates the review summary of the associated model.

```
use Fajarwz\LaravelReview\Models\Review;

$review = Review::find($id);
$review->approve();
```

#### Unapprove a Review

[](#unapprove-a-review)

To unapprove a review, use the `unapprove()` method. This sets the `approved_at` timestamp to null, indicating that the review is no longer approved. It also updates the review summary of the associated model to decrement the rating count if necessary.

```
$review = Review::find($id);
$review->unapprove();
```

#### Check If a Review Is Approved

[](#check-if-a-review-is-approved)

To check if a review is approved, use the `isApproved()` method. This method returns true if the `approved_at` timestamp is not null, and false otherwise.

```
$review = Review::find($id);
if ($review->isApproved()) {
    // The review is approved
}
```

#### Query Approved Reviews

[](#query-approved-reviews)

By default, the Review model applies a global scope to only include approved reviews. To query only approved reviews, you can use the model's standard query methods:

```
$approvedReviews = Review::all();
```

#### Query Unapproved Reviews

[](#query-unapproved-reviews)

To include unapproved reviews in your query, use the `withUnapproved()` method. This removes the global scope that filters out unapproved reviews, allowing you to query both approved and unapproved reviews.

```
$allReviews = Review::withUnapproved()->get();
```

#### Get the Reviewer

[](#get-the-reviewer)

To get the model that reviewed the item, use the `reviewer()` method. This method returns a polymorphic relationship to the reviewer model.

```
$review = Review::find($id);
$reviewer = $review->reviewer;
```

#### Get the Reviewable Model

[](#get-the-reviewable-model)

To get the model that was reviewed, use the `reviewable()` method. This method returns a polymorphic relationship to the reviewed model.

```
$review = Review::find($id);
$reviewable = $review->reviewable;
```

### ReviewSummary Model

[](#reviewsummary-model)

The `Fajarwz\LaravelReview\Models\ReviewSummary` model represents a summary of reviews for a specific reviewable model.

#### Attributes

[](#attributes)

- `average_rating`: The average rating of all reviews for the reviewable model.
- `review_count`: The total number of reviews for the reviewable model.

#### Get the Reviewable Model

[](#get-the-reviewable-model-1)

The `reviewable()` method defines a polymorphic relationship to the model that is being reviewed. It allows you to access the model that this review summary belongs to.

```
use Fajarwz\LaravelReview\Models\ReviewSummary;

$reviewSummary = ReviewSummary::find($id);
$reviewable = $reviewSummary->reviewable;
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

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

[](#contributing)

We welcome contributions. Please open [issues](https://github.com/fajarwz/laravel-review/issues) or [pull requests](https://github.com/fajarwz/laravel-review/pulls) with your suggestions or improvements.

Getting Help
------------

[](#getting-help)

For questions, discussions, or seeking assistance, please use the [GitHub Discussions](https://github.com/fajarwz/laravel-review/discussions) forum. This will help keep issues focused on bug reports and feature requests.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please contact

Credits
-------

[](#credits)

- [fajarwz](https://github.com/fajarwz)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity42

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

Total

3

Last Release

623d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ea2780b1aa53c148d514af675a782bbe617bb73cf7820cdb78b822cf26da74a3?d=identicon)[fajarwz](/maintainers/fajarwz)

---

Top Contributors

[![fajarwz](https://avatars.githubusercontent.com/u/39845286?v=4)](https://github.com/fajarwz "fajarwz (40 commits)")

---

Tags

laravellaravel-packagelibrariespackagesphpratingsreviewslaravelreviewRatingfajarwzlaravel-review

###  Code Quality

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[willvincent/laravel-rateable

Allows multiple models to be rated with a fivestar like system.

416452.0k3](/packages/willvincent-laravel-rateable)[codebyray/laravel-review-rateable

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

310351.9k](/packages/codebyray-laravel-review-rateable)[ghanem/rating

Rating system for Laravel

8615.5k](/packages/ghanem-rating)[nikaia/nova-rating-field

Add start rating field to Laravel Nova

42258.6k](/packages/nikaia-nova-rating-field)[trexology/reviewrateable

Rating syetem for Laravel 5

3514.4k](/packages/trexology-reviewrateable)

PHPackages © 2026

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