• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

mohamednagy/Laravel-rating: Laravel package that allows you to rate, like & ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

mohamednagy/Laravel-rating

开源软件地址(OpenSource Url):

https://github.com/mohamednagy/Laravel-rating

开源编程语言(OpenSource Language):

PHP 100.0%

开源软件介绍(OpenSource Introduction):

               

New Maintainer

This package now maintined by Ahmed Nagi

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 Nagy\LaravelRating\Traits\Rate\CanRate;

class User extends Model
{
    use CanRate;

include Rateable trait to your model that will be rateable

use Nagy\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 Nagy\LaravelRating\Traits\Vote\CanVote;

class User extends Model
{
    use CanVote;

include Votable trait to your model that will be votable

use Nagy\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 Nagy\LaravelRating\Traits\Like\CanLike;

class User extends Model
{
    use CanLike;

include Likeable trait to your model that will be likeable

use Nagy\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 nagy/laravel-rating

for laravel 5.*

composer require nagy/laravel-rating:^1.2

in your config/app.php

    'providers' => [
        ...
        Nagy\LaravelRating\LaravelRatingServiceProvider::class
    ],

    'aliases' => [
        ...
        "LaravelRating" => \Nagy\LaravelRating\LaravelRatingFacade::class,
    ]

You don't need this step in laravel5.5 package:discover will do the job :)

publish the migrations

php artisan vendor:publish --tag=laravelRatings

run the migrations

php artisan migrate



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap