PHPackages                             abdulmananse/laravel-like-dislike - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. abdulmananse/laravel-like-dislike

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

abdulmananse/laravel-like-dislike
=================================

👍 User like and dislike features for Laravel Application.

191PHP

Since Dec 9Pushed 2y ago1 watchersCompare

[ Source](https://github.com/abdulmananse/laravel-like-dislike)[ Packagist](https://packagist.org/packages/abdulmananse/laravel-like-dislike)[ RSS](/packages/abdulmananse-laravel-like-dislike/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Like Dislike
====================

[](#laravel-like-dislike)

👍 User like and dislike features for Laravel Application.

Installing
----------

[](#installing)

```
composer require abdulmananse/laravel-like-dislike
```

### Configuration

[](#configuration)

This step is optional

```
php artisan vendor:publish --provider="Abdulmananse\\LaravelLikeDislike\\LikeServiceProvider" --tag=config
```

### Migrations

[](#migrations)

This step is also optional, if you want to custom likes table, you can publish the migration files:

```
php artisan vendor:publish --provider="Abdulmananse\\LaravelLikeDislike\\LikeServiceProvider" --tag=migrations
```

Usage
-----

[](#usage)

### Traits

[](#traits)

#### `Abdulmananse\LaravelLikeDislike\Traits\Liker`

[](#abdulmananselaravellikedisliketraitsliker)

```
use Illuminate\Foundation\Auth\User as Authenticatable;
use Abdulmananse\LaravelLikeDislike\Traits\Liker;

class User extends Authenticatable
{
    use Liker;

}
```

#### `Abdulmananse\LaravelLikeDislike\Traits\Likeable`

[](#abdulmananselaravellikedisliketraitslikeable)

```
use Illuminate\Database\Eloquent\Model;
use Abdulmananse\LaravelLikeDislike\Traits\Likeable;

class Post extends Model
{
    use Likeable;

}
```

### API

[](#api)

```
$user = User::find(1);
$post = Post::find(2);

$user->like($post);
$user->dislike($post);
$user->unlike($post);

$user->toggleLike($post);
$user->toggleDislike($post);

$user->hasLiked($post);
$user->hasDisliked($post);
$post->isLikedBy($user);
$post->isDislikedBy($user);
```

Get user likes with pagination:

```
$likes = $user->likes()->with('likeable')->paginate(20);

foreach ($likes as $like) {
    $like->likeable; // App\Post instance
}
```

Get user dislikes with pagination:

```
$dislikes = $user->dislikes()->with('likeable')->paginate(20);

foreach ($dislikes as $dislike) {
    $dislike->likeable; // App\Post instance
}
```

Get object likers:

```
foreach($post->likers as $user) {
    // echo $user->name;
}
```

with pagination:

```
$likers = $post->likers()->paginate(20);

foreach($likers as $user) {
    // echo $user->name;
}
```

Get object dislikers:

```
foreach($post->dislikers as $user) {
    // echo $user->name;
}
```

with pagination:

```
$dislikers = $post->dislikers()->paginate(20);

foreach($dislikers as $user) {
    // echo $user->name;
}
```

### Aggregations

[](#aggregations)

```
// all likes
$user->likes()->count();

// short way
$user->totalLikes;

// with type
$user->likes()->withType(Post::class)->count();

// all dislikes
$user->dislikes()->count();

// short way
$user->totalDislikes;

// with type
$user->dislikes()->withType(Post::class)->count();

// likers count
$post->likers()->count();

// short way
$post->totalLikers

// dislikers count
$post->dislikers()->count();

// short way
$post->totalDislikers
```

List with `*_count` attribute:

```
// likes_count
$users = User::withCount('likes')->get();

foreach($users as $user) {
    // $user->likes_count;
}

// dislikes_count
$users = User::withCount('dislikes')->get();

foreach($users as $user) {
    // $user->dislikes_count;
}

// likers_count
$posts = Post::withCount('likers')->get();

foreach($posts as $post) {
    // $post->likers_count;
}

// dislikers_count
$posts = Post::withCount('dislikers')->get();

foreach($posts as $post) {
    // $post->dislikers_count;
}
```

### 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:

```
// Liker
$users = User::with('likes')->get();

foreach($users as $user) {
    $user->hasLiked($post);
}

// Disliker
$users = User::with('dislikes')->get();

foreach($users as $user) {
    $user->hasDisliked($post);
}

// Likeable
$posts = App\Post::with('likes')->get();
// or
$posts = App\Post::with('likers')->get();

foreach($posts as $post) {
    $post->isLikedBy($user);
}

// Dislike
$posts = Post::with('dislikes')->get();
// or
$posts = Post::with('dislikers')->get();

foreach($posts as $post) {
    $post->isDislikedBy($user);
}
```

Of course we have a better solution, which can be found in the following section：

### Attach user like/dislike status to likeable collection

[](#attach-user-likedislike-status-to-likeable-collection)

You can use `Liker::attachLikeDislikeStatus($likeables)` to attach the user like status, it will attach `has_liked` and `has_disliked` attributes to each model of `$likeables`:

#### For model

[](#for-model)

```
$post = Post::find(1);

$post = $user->attachLikeDislikeStatus($post);

// result
[
    "id" => 1
    "title" => "Add socialite login support."
    "has_liked" => true
    "has_disliked" => false
],
```

#### For `Collection | Paginator | LengthAwarePaginator | array`:

[](#for-collection--paginator--lengthawarepaginator--array)

```
$posts = Post::oldest('id')->get();

$posts = $user->attachLikeDislikeStatus($posts);

$posts = $posts->toArray();

// result
[
  [
    "id" => 1
    "title" => "Post title1"
    "has_liked" => true
    "has_disliked" => false
  ],
  [
    "id" => 2
    "title" => "Post title2"
    "has_liked" => fasle
    "has_disliked" => true
  ],
  [
    "id" => 3
    "title" => "Post title3"
    "has_liked" => true
    "has_disliked" => false
  ],
]
```

#### For pagination

[](#for-pagination)

```
$posts = Post::paginate(20);

$user->attachLikeDislikeStatus($posts);
```

### Events

[](#events)

**Event****Description**`Abdulmananse\LaravelLikeDislike\Events\Liked`Triggered when the relationship is created.`Abdulmananse\LaravelLikeDislike\Events\Unliked`Triggered when the relationship is deleted.License
-------

[](#license)

MIT

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity20

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1fad6171d41cbf825ce8c0e175026cfde2f5a8ea8c081806d8686edb06259e86?d=identicon)[abdulmananse](/maintainers/abdulmananse)

---

Top Contributors

[![abdulmananse](https://avatars.githubusercontent.com/u/19402164?v=4)](https://github.com/abdulmananse "abdulmananse (1 commits)")

### Embed Badge

![Health badge](/badges/abdulmananse-laravel-like-dislike/health.svg)

```
[![Health](https://phpackages.com/badges/abdulmananse-laravel-like-dislike/health.svg)](https://phpackages.com/packages/abdulmananse-laravel-like-dislike)
```

###  Alternatives

[bacon/bacon-string-utils

BaconStringUtils contain utitilies to work with strings.

27646.5k1](/packages/bacon-bacon-string-utils)

PHPackages © 2026

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