sumantablog/laravel-review-rateable
Composer 安装命令:
composer require sumantablog/laravel-review-rateable
包简介
Review & Rating system for Laravel
README 文档
README
Review Rateable system for laravel 5. and 6. You can rate your models by:
- Overall Rating
- Customer Service Rating
- Quality Rating
- Friendly Rating
- Price Rating
You can also set whether the model being rated is recommended.
Installation
First, pull in the package through Composer.
composer require sundarocs/laravel-review-rateable
And then include the service provider within app/config/app.php. Note: If you are running Laravel 5.5+ this will be auto loaded for you.
'providers' => [ Sumantablog\ReviewRateable\ReviewRateableServiceProvider::class ];
At last you need to publish and run the migration.
php artisan vendor:publish --provider="Sumantablog\ReviewRateable\ReviewRateableServiceProvider" --tag="migrations"
Run the migration
php artisan migrate
Setup a Model
<?php namespace App; use Sumantablog\ReviewRateable\Contracts\ReviewRateable; use Sumantablog\ReviewRateable\Traits\ReviewRateable as ReviewRateableTrait; use Illuminate\Database\Eloquent\Model; class Post extends Model implements ReviewRateable { use ReviewRateableTrait; }
Create a rating
When creating a rating you can specify whether the rating is approved or not by adding approved to the array. This is optional and if left out the default is not approved to allow for review before posting.
$user = User::first(); $post = Post::first(); $rating = $post->rating([ 'title' => 'This is a test title', 'body' => 'And we will add some shit here', 'customer_service_rating' => 5, 'quality_rating' => 5, 'friendly_rating' => 5, 'pricing_rating' => 5, 'rating' => 5, 'recommend' => 'Yes', 'approved' => true, // This is optional and defaults to false ], $user); dd($rating);
Update a rating
$rating = $post->updateRating(1, [ 'title' => 'new title', 'body' => 'new body', 'customer_service_rating' => 1, 'quality_rating' => 1, 'friendly_rating' => 3, 'pricing_rating' => 4, 'rating' => 4, 'recommend' => 'No', 'approved' => true, // This is optional and defaults to false ]);
Marking review as approved
$rating = $post->updateRating(1, ['approved' => true]);
Delete a rating:
$post->deleteRating(1);
Fetch approved or not approved reviews/ratings for a particular resource
// Get approved ratings $ratings = $post->getApprovedRatings($post->id, 'desc'); // Get not approved ratings $ratings = $post->getNotApprovedRatings($post->id, 'desc'); // Get all ratings whether approved or not $ratings = $post->getAllRatings($post->id, 'desc'); // Get the most recent ratings (limit and sort are optional) // Limit default is 5, sort default is desc $ratings = $post->getRecentRatings($post->id, 5, 'desc'); // Get the most recent user ratings (limit and sort are optional) // Limit default is 5, approved default is true, sort default is desc $userRatings = $post->getRecentUserRatings($user->id, 5, true, 'desc');
Fetch the average rating:
// Get Overall Average Rating $post->averageRating() // Get Customer Service Average Rating $post->averageCustomerServiceRating() // Get Quality Average Rating $post->averageQualityRating() // Get Friendly Average Rating $post->averageFriendlyRating() // Get Price Average Rating $post->averagePricingRating()
or
$post->averageRating(2) //round to 2 decimal place $post->averageRating(null, true) //get only approved average rating
Get all ratings:
$post = Post::first(); $ratings = $post->getAllRatings($post->id);
Count total rating:
$post->countRating()
Fetch the rating percentage.
This is also how you enforce a maximum rating value.
$post->ratingPercent() $post->ratingPercent(10)); // Ten star rating system // Note: The value passed in is treated as the maximum allowed value. // This defaults to 5 so it can be called without passing a value as well.
Note
This is a fork from Trexology's - Original Code - laravel-reviewRateable .
Please note that this code is not used in the original and is not maintained.
sumantablog/laravel-review-rateable 适用场景与选型建议
sumantablog/laravel-review-rateable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 44 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 07 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「Rating」 「Ratable」 「reviewable」 「Review-Rateable」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sumantablog/laravel-review-rateable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sumantablog/laravel-review-rateable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sumantablog/laravel-review-rateable 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This Extension integrates a credit check and more made by the LEONEX Risk Management Platform into your order process. Extensive configuration and evaluation options is provided in the Platform
Rating system for Laravel
Rating syetem for Laravel 5
Rating syetem for Laravel 5
EMS Company Star Rating plugin
Alfabank REST API integration
统计信息
- 总下载量: 44
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-07-31