🎉 This package helps you to add user based vote system to your model.
This project code is basically the same as laravel-follow.
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;
}
$comment = Comment::find(1);
$user->upVote($comment);
$comment = Comment::find(1);
$user->downVote($comment);
$comment = Comment::find(1);
$user->cancelVote($comment);
$user->votedItems(Comment::class)->get();
$comment = Comment::find(1);
$user->hasVoted($comment);
$comment = Comment::find(1);
$user->hasUpVoted($comment);
$comment = Comment::find(1);
$user->hasDownVoted($comment);
$comment->voters();
$comment->countVoters();
$comment->countUpVoters();
$comment->countDownVoters();
$comment->isVotedBy(1);
MIT