multek / laravel-review
Polymorphic review and rating system for Laravel Eloquent models with caching, moderation, and events.
v1.0.0
2026-04-01 17:59 UTC
Requires
- php: ^8.2
- illuminate/contracts: ^11.0|^12.0|^13.0
- illuminate/support: ^11.0|^12.0|^13.0
Requires (Dev)
- laravel/pint: ^1.0
- orchestra/testbench: ^9.0|^10.0|^11.0
- pestphp/pest: ^3.0|^4.0
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 createdReviewUpdated— fired when a review is updatedReviewApproved— fired when status changes to approvedReviewRejected— fired when status changes to rejectedReviewDeleted— 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