laravel-vote

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

  • Owner: jcc/laravel-vote
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

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

Main metrics

Overview
Name With Ownerjcc/laravel-vote
Primary LanguagePHP
Program languagePHP (Language Count: 1)
Platform
License:MIT License
所有者活动
Created At2017-04-11 12:21:01
Pushed At2023-06-07 04:30:24
Last Commit At2023-06-07 12:30:24
Release Count9
Last Release Namev2.0.0 (Posted on )
First Release Namev1.0.0 (Posted on 2017-04-14 23:49:45)
用户参与
Stargazers Count136
Watchers Count3
Fork Count15
Commits Count43
Has Issues Enabled
Issues Count5
Issue Open Count2
Pull Requests Count5
Pull Requests Open Count0
Pull Requests Close Count0
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private