multek/laravel-review

Polymorphic review and rating system for Laravel Eloquent models with caching, moderation, and events.

Maintainers

Package info

github.com/Multek-Company/laravel-review

pkg:composer/multek/laravel-review

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-04-01 17:59 UTC

This package is auto-updated.

Last update: 2026-04-01 18:25:27 UTC


README

Polymorphic review and rating system for Laravel Eloquent models with caching, moderation, and events.

Installation

composer require multek/laravel-review

Publish and run migrations:

php artisan vendor:publish --tag=review-migrations
php artisan migrate

Optionally publish the config:

php artisan vendor:publish --tag=review-config

Usage

Setup Models

Add HasReviews to any model that can be reviewed:

use Multek\Review\Traits\HasReviews;

class Product extends Model
{
    use HasReviews;
}

Add CanReview to models that can author reviews:

use Multek\Review\Traits\CanReview;

class User extends Model
{
    use CanReview;
}

Creating Reviews

// Via the reviewable model
$product->addReview([
    'rating' => 5,
    'title' => 'Amazing!',
    'body' => 'Best product ever.',
], $user);

// Via the author model
$user->review($product, [
    'rating' => 4,
    'body' => 'Pretty good.',
]);

Review Summary (Cached)

$summary = $product->review_summary;

$summary->average_rating;       // 4.5
$summary->total_count;          // 42
$summary->rating_distribution;  // [1 => 2, 2 => 3, 3 => 5, 4 => 12, 5 => 20]
$summary->percentage(5);        // 47.6

Moderation

$review->approve();
$review->reject();
$review->addReply('Thank you for your feedback!');

$review->isApproved();
$review->isPending();
$review->isRejected();

Query Scopes

// On Review model
Review::approved()->get();
Review::pending()->get();
Review::byAuthor($user)->get();

// On reviewable models
Product::orderByAverageRating('desc')->get();
Product::orderByReviewCount('desc')->get();
Product::hasMinimumRating(4)->get();
Product::hasMinimumReviews(10)->get();
Product::withReviewSummary()->get();

Events

  • ReviewCreated — fired when a review is created
  • ReviewUpdated — fired when a review is updated
  • ReviewApproved — fired when status changes to approved
  • ReviewRejected — fired when status changes to rejected
  • ReviewDeleted — fired when a review is deleted

Configuration

return [
    'min_rating' => 1,
    'max_rating' => 5,
    'allow_decimals' => false,
    'auto_approve' => true,
    'cache' => [
        'enabled' => true,
        'ttl' => 3600,
        'store' => null,
        'prefix' => 'review_',
    ],
    'review_model' => \Multek\Review\Models\Review::class,
];

License

MIT