dutta/laravel-rating
Composer 安装命令:
composer require dutta/laravel-rating
包简介
manage rating column for elqouent models
关键字:
README 文档
README
New Maintainer
This package now maintined by Dutta Fachrezy
Laravel-Ratings
Laravel package that allows you to rate, like & dislike or vote up & down your models with a simple and clear way.
If you see this packge can help, Don't skimp on me with a star :)
Rating
include CanRate trait into your user model to apply rating functions
use Dutta\LaravelRating\Traits\Rate\CanRate; class User extends Model { use CanRate;
include Rateable trait to your model that will be rateable
use Dutta\LaravelRating\Traits\Rate\Rateable; class Post extends Model { use Rateable;
now you can rate your models as the following:
$user->rate($postModel, 5);
also you can unrate your models as the following:
$user->unrate($postModel); // alternatively $user->rate($postModel, -1); // or $user->rate($postModel, false); // or $user->rate($postModel, null);
get the average ratings of a model
$post->ratingsAvg();
get the total count of ratings of a model
$post->ratingsCount();
get the rated models by a user
$user->rated(); // returns a collection of rated models
Voting
include CanVote trait into your user model to apply rating functionalties
use Dutta\LaravelRating\Traits\Vote\CanVote; class User extends Model { use CanVote;
include Votable trait to your model that will be votable
use Dutta\LaravelRating\Traits\Vote\Votable; class Post extends Model { use Votable;
now you can vote your model as the following:
// up vote or +1 your model $user->upVote($postModel); // down vote or -1 your model $user->downVote($postModel);
get total votes count
$postModel->votesCount();
get total up votes count
$postModel->upVotesCount();
get total down votes count
$postModel->downVotesCount();
get the up voted models by a user
$user->upVoted(); // returns a collection of up voted models
get the down voted models by a user
$user->downVoted(); // returns a collection of down voted models
get the total voted models by a user
$user->voted(); // returns a collection of total voted models;
Like & Dislike
include CanLike trait into your user model to apply like and dislike functionalties
use Dutta\LaravelRating\Traits\Like\CanLike; class User extends Model { use CanLike;
include Likeable trait to your model that will be likeable
use Dutta\LaravelRating\Traits\Like\Likeable; class Post extends Model { use Likeable;
now you can like your model as the following:
// like $user->like($postModel); // dislike $user->dislike($postModel);
get total likes count
$postModel->likesCount();
get total dislikes count
$postModel->dislikesCount();
get total likes and dislikes count
$postModel->likesDislikesCount();
get the liked models by a user
$user->liked(); // return a collection of liked models;
get the disliked models by a user
$user->disliked(); // return a collection of disliked models;
get the total liked and disliked models by a user
$user->likedDisliked(); // return a collection of liked and disliked models;
Install
for laravel 8.* , 7.* , 6.*
composer require dutta/laravel-rating
in your config/app.php
'providers' => [ ... Dutta\LaravelRating\LaravelRatingServiceProvider::class ], 'aliases' => [ ... "LaravelRating" => \Dutta\LaravelRating\LaravelRatingFacade::class, ]
You don't need this step in laravel5.5
package:discoverwill do the job :)
publish the migrations
php artisan vendor:publish --tag=laravelRatings
run the migrations
php artisan migrate
dutta/laravel-rating 适用场景与选型建议
dutta/laravel-rating 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 23 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 07 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel-rating」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dutta/laravel-rating 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dutta/laravel-rating 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dutta/laravel-rating 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
manage rating column for elqouent models
manage rating column for elqouent models
Associate ratings to any Eloquent model
5 star rating for eloquent
Manage rating column for elqouent models
Associate ratings to any Eloquent model
统计信息
- 总下载量: 23
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-07-30
