itmosoft / laravel-reviews
Polymorphic ratings and reviews for Laravel applications.
Requires
- php: ^8.3
- illuminate/database: ^12.0 || ^13.0
- illuminate/events: ^12.0 || ^13.0
- illuminate/support: ^12.0 || ^13.0
Requires (Dev)
- orchestra/testbench: ^10.0 || ^11.0
- phpunit/phpunit: ^11.0 || ^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Polymorphic ratings and reviews for Laravel 12 and 13.
Features
- Attach reviews to any Eloquent model through a polymorphic relation.
- Configurable integer rating range (default 1–5).
- Pending, approved and rejected moderation states.
- Optional reviewer/customer identifier and verified-purchase flag.
- Prevent duplicate reviews by the same reviewer for the same reviewable by default.
- Approved-review counts and average ratings.
- Configurable table prefix and review model.
- Laravel package auto-discovery and migrations.
Requirements
- PHP 8.3+
- Laravel 12 or 13
Installation
composer require itmosoft/laravel-reviews php artisan vendor:publish --tag=reviews-config php artisan migrate
Add reviews to a model
use Illuminate\Database\Eloquent\Model; use ItmoSoft\Reviews\Concerns\HasReviews; class Product extends Model { use HasReviews; }
Create and moderate a review
use ItmoSoft\Reviews\ReviewsManager; $review = app(ReviewsManager::class)->create($product, [ 'reviewer_id' => $customer->id, 'rating' => 5, 'title' => 'Excellent', 'body' => 'Great product.', 'is_verified_purchase' => true, ]); app(ReviewsManager::class)->approve($review);
New reviews default to pending. Set reviews.moderation.enabled to false to create reviews as approved.
Read rating data
$product->approvedReviews()->latest()->get(); $product->averageRating(); $product->reviewsCount(); $average = app(ReviewsManager::class)->averageRating($product); $count = app(ReviewsManager::class)->count($product);
Only approved reviews are included in aggregate calculations.
Configuration
| Key | Default | Purpose |
|---|---|---|
table_prefix |
itmosoft_ |
Prefix for the reviews table |
ratings.minimum |
1 |
Minimum allowed rating |
ratings.maximum |
5 |
Maximum allowed rating |
moderation.enabled |
true |
Whether new reviews require moderation |
moderation.default_status |
pending |
Initial status when moderation is enabled |
allow_multiple_reviews |
false |
Allow multiple reviews from the same reviewer for one reviewable |
The package stores reviewer_id without a foreign key because customer/user tables vary between applications. The host application must enforce authentication, authorization, ownership, purchase verification, rate limits, spam prevention and content validation. Do not trust is_verified_purchase from an untrusted client; set it only after checking the order in your application.
Testing
composer install
composer validate --strict
composer test
Scope
This package provides persistence and domain operations only. It does not ship HTTP routes, controllers, API resources, UI, product/order integrations, image uploads, notifications, or automatic purchase verification. The application owns those policies and integrations.
License
MIT.