jcc/laravel-vote
Larablocks Analysis
jcc/laravel-vote works with Laravel 5 to 8 (latest release v2.0.0, Mar 14, 2021), all past end of life (the last on Jan 24, 2023): no more fixes, even for security.
Recommendation checks
Not advisedNot advised: no release or commit in over 2 years.
- No release or commit in over 2 years
- Supports only Laravel 5 to 8, past end of life since Jan 24, 2023
- No release in the last 12 months (last: Mar 14, 2021)
- 673 downloads a month (needs 10,000)
- 134 GitHub stars (at least 100)
State
Likely abandoned- No release or commit in over 2 years.
- Last stable release: Mar 14, 2021.
- No releases in the last 12 months.
- First released: Apr 14, 2017.
- Monthly downloads: 673, up 587% from six months ago.
- 2 open issues on GitHub.
Data from Packagist and GitHub, checked by Larablocks on Nov 30, 2026.
| Install | |
|---|---|
composer require jcc/laravel-vote |
|
| Latest Version: | v2.0.0 |
| PHP: | >=7.2 |
| Laravel: | 5 – 8 |
| License: | MIT |
| Last Updated: | Jun 7, 2023 |
| Links: | GitHub · Packagist |
Laravel Vote System
:tada: This package helps you to add user based vote system to your model.
Installation
You can install the package using Composer:
$ composer require "jcc/laravel-vote:~2.0"
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\Traits\Voter;
class User extends Model
{
use Voter;
}
Or use CanBeVoted in Comment model:
use Jcc\LaravelVote\Traits\Votable;
class Comment extends Model
{
use Votable;
}
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->getVotedItems(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()->get();
Count comment voters
$comment->voters()->count();
Get comment up voters
$comment->upVoters()->get();
Count comment up voters
$comment->upVoters()->count();
Get comment down voters
$comment->downVoters()->get();
Count comment down voters
$comment->downVoters()->count();
Check if voted by
$user = User::find(1);
$comment->isVotedBy($user);
Check if up voted by
$user = User::find(1);
$comment->isUpVotedBy($user);
Check if down voted by
$user = User::find(1);
$comment->isDownVotedBy($user);
N+1 issue
To avoid the N+1 issue, you can use eager loading to reduce this operation to just 2 queries. When querying, you may specify which relationships should be eager loaded using the with method:
// Voter
$users = User::with('votes')->get();
foreach($users as $user) {
$user->hasVoted($comment);
}
// Votable
$comments = Comment::with('voters')->get();
foreach($comments as $comment) {
$comment->isVotedBy($user);
}
Events
| Event | Description |
|---|---|
Jcc\LaravelVote\Events\Voted |
Triggered when the relationship is created or updated. |
Jcc\LaravelVote\Events\CancelVoted |
Triggered when the relationship is deleted. |
Reference
License
Related Packages
Powerful PHP database abstraction layer (DBAL) with many features for database s...
Laravel Serializable Closure provides an easy and secure way to serialize closur...
Cli error handling for console/command-line PHP applications.
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v2.0.0 | >=7.2 | ^5.5| | MIT | |
| v1.1.4 | >=5.5.9 | MIT | ||
| v1.1.3 | >=5.5.9 | MIT | ||
| v1.1.2 | >=5.5.9 | MIT | ||
| v1.1.1 | >=5.5.9 | MIT | ||
| v1.1.0 | >=5.5.9 | MIT | ||
| v1.0.1 | >=5.5.9 | MIT | ||
| v1.0.0 | >=5.5.9 | MIT |