laravel-vote

:tada: The package helps you to add user based vote system to your model.

  • 所有者: jcc/laravel-vote
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

Laravel 5 Vote System

:tada: This package helps you to add user based vote system to your model.

This project code is basically the same as laravel-follow.

Installation

You can install the package using Composer:

$ composer require jcc/laravel-vote -vvv

Then add the service provider to config/app.php:

Jcc\LaravelVote\VoteServiceProvider::class

Publish the migrations file:

$ php artisan vendor:publish --provider="Jcc\LaravelVote\VoteServiceProvider" --tag="migrations"

Finally, use VoteTrait in User model:

use Jcc\LaravelVote\Vote;

class User extends Model
{
    use Vote;
}

Or use CanBeVoted in Comment model:

use Jcc\LaravelVote\CanBeVoted;

class Comment extends Model
{
    use CanBeVoted;

    protected $vote = User::class;
}

Usage

For User model

Up vote a comment or comments

$comment = Comment::find(1);

$user->upVote($comment);

Down vote a comment or comments

$comment = Comment::find(1);

$user->downVote($comment);

Cancel vote a comment or comments

$comment = Comment::find(1);

$user->cancelVote($comment);

Get user has voted comment items

$user->votedItems(Comment::class)->get();

Check if user has up or down vote

$comment = Comment::find(1);

$user->hasVoted($comment);

Check if user has up vote

$comment = Comment::find(1);

$user->hasUpVoted($comment);

Check if user has down vote

$comment = Comment::find(1);

$user->hasDownVoted($comment);

For Comment model

Get comment voters

$comment->voters();

Count comment voters

$comment->countVoters();

Count comment up voters

$comment->countUpVoters();

Count comment down voters

$comment->countDownVoters();

Check if voted by

$comment->isVotedBy(1);

Reference

laravel-follow

License

MIT

主要指标

概览
名称与所有者jcc/laravel-vote
主编程语言PHP
编程语言PHP (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2017-04-11 12:21:01
推送于2023-06-07 04:30:24
最后一次提交2023-06-07 12:30:24
发布数9
最新版本名称v2.0.0 (发布于 )
第一版名称v1.0.0 (发布于 2017-04-14 23:49:45)
用户参与
星数136
关注者数3
派生数15
提交数43
已启用问题?
问题数5
打开的问题数2
拉请求数5
打开的拉请求数0
关闭的拉请求数0
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?