PHPackages                             jimchen/laravel-vote - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. jimchen/laravel-vote

ActiveLibrary

jimchen/laravel-vote
====================

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

v1.0.0(4y ago)1807MITPHPPHP &gt;=7.2

Since Mar 15Pushed 4y ago1 watchersCompare

[ Source](https://github.com/JimChenWYU/laravel-vote)[ Packagist](https://packagist.org/packages/jimchen/laravel-vote)[ RSS](/packages/jimchen-laravel-vote/feed)WikiDiscussions main Synced today

READMEChangelog (4)Dependencies (6)Versions (5)Used By (0)

Laravel Vote System
===================

[](#laravel-vote-system)

[![Test Status](https://github.com/JimChenWYU/laravel-vote/workflows/Test/badge.svg)](https://github.com/JimChenWYU/laravel-vote/actions)[![Check & fix styling](https://github.com/JimChenWYU/laravel-vote/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/JimChenWYU/laravel-vote/actions/workflows/php-cs-fixer.yml)[![Latest Stable Version](https://camo.githubusercontent.com/85ce396c0f0de27e4e22eeea1da930fe34bb1160354e25c4e082c16b0e716181/68747470733a2f2f706f7365722e707567782e6f72672f6a696d6368656e2f6c61726176656c2d766f74652f762f737461626c652e737667)](https://packagist.org/packages/jimchen/laravel-vote)[![License](https://camo.githubusercontent.com/6d59a43e5235f9f3795cc528403463736f8c1c7f78adcca9e0e667630fdfc3b2/68747470733a2f2f706f7365722e707567782e6f72672f6a696d6368656e2f6c61726176656c2d766f74652f6c6963656e7365)](https://packagist.org/packages/jimchen/laravel-vote)

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

> fork from [jcc/laravel-vote](https://github.com/jcc/laravel-vote)

Installation
------------

[](#installation)

You can install the package using Composer:

```
$ composer require "jimchen/laravel-vote"
```

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

```
JimChen\LaravelVote\VoteServiceProvider::class
```

Publish the migrations file:

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

Finally, use VoteTrait in User model:

```
use JimChen\LaravelVote\Traits\Voter;

class User extends Model
{
    use Voter;
}
```

Or use CanBeVoted in Comment model:

```
use JimChen\LaravelVote\Traits\Votable;

class Comment extends Model
{
    use Votable;
}
```

Usage
-----

[](#usage)

### For User model

[](#for-user-model)

#### Up vote a comment or comments

[](#up-vote-a-comment-or-comments)

```
$comment = Comment::find(1);

$user->upVote($comment);
```

### Down vote a comment or comments

[](#down-vote-a-comment-or-comments)

```
$comment = Comment::find(1);

$user->downVote($comment);
```

#### Cancel vote a comment or comments

[](#cancel-vote-a-comment-or-comments)

```
$comment = Comment::find(1);

$user->cancelVote($comment);
```

#### Get user has voted comment items

[](#get-user-has-voted-comment-items)

```
$user->getVotedItems(Comment::class)->get();
```

#### Check if user has up or down vote

[](#check-if-user-has-up-or-down-vote)

```
$comment = Comment::find(1);

$user->hasVoted($comment);
```

#### Check if user has up vote

[](#check-if-user-has-up-vote)

```
$comment = Comment::find(1);

$user->hasUpVoted($comment);
```

#### Check if user has down vote

[](#check-if-user-has-down-vote)

```
$comment = Comment::find(1);

$user->hasDownVoted($comment);
```

### For Comment model

[](#for-comment-model)

#### Get comment voters

[](#get-comment-voters)

```
$comment->voters()->get();
```

#### Count comment voters

[](#count-comment-voters)

```
$comment->voters()->count();
```

#### Get comment up voters

[](#get-comment-up-voters)

```
$comment->upVoters()->get();
```

#### Count comment up voters

[](#count-comment-up-voters)

```
$comment->upVoters()->count();
```

#### Get comment down voters

[](#get-comment-down-voters)

```
$comment->downVoters()->get();
```

#### Count comment down voters

[](#count-comment-down-voters)

```
$comment->downVoters()->count();
```

#### Check if voted by

[](#check-if-voted-by)

```
$user = User::find(1);

$comment->isVotedBy($user);
```

#### Check if up voted by

[](#check-if-up-voted-by)

```
$user = User::find(1);

$comment->isUpVotedBy($user);
```

#### Check if down voted by

[](#check-if-down-voted-by)

```
$user = User::find(1);

$comment->isDownVotedBy($user);
```

### N+1 issue

[](#n1-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

[](#events)

**Event****Description**`JimChen\LaravelVote\Events\Voted`Triggered when the relationship is created or updated.`JimChen\LaravelVote\Events\CancelVoted`Triggered when the relationship is deleted.Reference
---------

[](#reference)

- [laravel-follow](https://github.com/overtrue/laravel-follow)
- [laravel-like](https://github.com/overtrue/laravel-like)

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 53.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~22 days

Total

4

Last Release

1817d ago

Major Versions

v0.3-alpha → v1.0.02021-05-20

### Community

Maintainers

![](https://www.gravatar.com/avatar/20cebafc45fd6fc5f67bf655119a3b27e9b208e248f2d7f5c98fd6c0a101485b?d=identicon)[jimchen](/maintainers/jimchen)

---

Top Contributors

[![JimChenWYU](https://avatars.githubusercontent.com/u/12371374?v=4)](https://github.com/JimChenWYU "JimChenWYU (28 commits)")[![jcc](https://avatars.githubusercontent.com/u/12684082?v=4)](https://github.com/jcc "jcc (18 commits)")[![stephenahiggins](https://avatars.githubusercontent.com/u/12612312?v=4)](https://github.com/stephenahiggins "stephenahiggins (3 commits)")[![lex111](https://avatars.githubusercontent.com/u/4408379?v=4)](https://github.com/lex111 "lex111 (1 commits)")[![Seaony](https://avatars.githubusercontent.com/u/29486364?v=4)](https://github.com/Seaony "Seaony (1 commits)")[![sseffa](https://avatars.githubusercontent.com/u/2960378?v=4)](https://github.com/sseffa "sseffa (1 commits)")

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jimchen-laravel-vote/health.svg)

```
[![Health](https://phpackages.com/badges/jimchen-laravel-vote/health.svg)](https://phpackages.com/packages/jimchen-laravel-vote)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[namu/wirechat

A Laravel Livewire messaging app for teams with private chats and group conversations.

54324.5k](/packages/namu-wirechat)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135192.6k5](/packages/statamic-rad-pack-runway)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
