multek/laravel-review
最新稳定版本:v1.0.0
Composer 安装命令:
composer require multek/laravel-review
包简介
Polymorphic review and rating system for Laravel Eloquent models with caching, moderation, and events.
README 文档
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
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-01