定制 multek/laravel-review 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固