PHPackages                             eslamfaroug/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. eslamfaroug/laravel-like-dislike

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

eslamfaroug/laravel-like-dislike
================================

👍 User like/dislike features for Laravel Application.

v1.5(2y ago)11.0k↓50%1MITPHP

Since Aug 10Pushed 2y ago1 watchersCompare

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

READMEChangelog (6)Dependencies (7)Versions (7)Used By (0)

Laravel Like
============

[](#laravel-like)

👍 User-like features for Laravel Application.

Installing
----------

[](#installing)

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

### Configuration

[](#configuration)

This step is optional

```
php artisan vendor:publish
```

### Migrations

[](#migrations)

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

```
php artisan vendor:publish
```

Usage
-----

[](#usage)

### Traits

[](#traits)

#### `EslamFaroug\LaravelLikeDislike\Traits\Liker`

[](#eslamfarouglaravellikedisliketraitsliker)

```
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use EslamFaroug\LaravelLikeDislike\Traits\Liker;

class User extends Authenticatable
{
    use Liker;

}
```

#### `EslamFaroug\LaravelLikeDislike\Traits\Likeable`

[](#eslamfarouglaravellikedisliketraitslikeable)

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

class Post extends Model
{
    use Likeable;

}
```

### API

[](#api)

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

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

$user->hasLiked($post);
$post->isLikedBy($user);

$user->dislike($post);
$user->undislike($post);
$user->toggleDislike($post);

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

Get user likes with pagination:

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

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

$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;
}

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

with pagination:

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

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

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

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

### Aggregations

[](#aggregations)

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

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

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

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

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

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

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 = User::withCount('likers')->get();

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

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

foreach($posts as $post) {
    // $post->dislikes_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 = App\User::with('likes')->get();

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

// Disliker
$users = App\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);
}

$posts = App\Post::with('dislikes')->get();
// or
$posts = App\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 status to likeable collection

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

You can use `Liker::attachLikeStatus($likeables)` to attach the user like status, it will attach `has_liked` attribute to each model of `$likeables`:

#### For model

[](#for-model)

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

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

// result
[
    "id" => 1
    "title" => "Add socialite login support."
    "created_at" => "2021-05-20T03:26:16.000000Z"
    "updated_at" => "2021-05-20T03:26:16.000000Z"
    "has_liked" => true
 ],

$post = Post::find(1);

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

// result
[
    "id" => 1
    "title" => "Add socialite login support."
    "created_at" => "2021-05-20T03:26:16.000000Z"
    "updated_at" => "2021-05-20T03:26:16.000000Z"
    "has_disliked" => true
 ],
```

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

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

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

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

$posts = $posts->toArray();

// result
[
  [
    "id" => 1
    "title" => "Post title1"
    "created_at" => "2021-05-20T03:26:16.000000Z"
    "updated_at" => "2021-05-20T03:26:16.000000Z"
    "has_liked" => true
  ],
  [
    "id" => 2
    "title" => "Post title2"
    "created_at" => "2021-05-20T03:26:16.000000Z"
    "updated_at" => "2021-05-20T03:26:16.000000Z"
    "has_liked" => fasle
  ],
  [
    "id" => 3
    "title" => "Post title3"
    "created_at" => "2021-05-20T03:26:16.000000Z"
    "updated_at" => "2021-05-20T03:26:16.000000Z"
    "has_liked" => true
  ],
]
```

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

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

$posts = $posts->toArray();

// result
[
  [
    "id" => 1
    "title" => "Post title1"
    "created_at" => "2021-05-20T03:26:16.000000Z"
    "updated_at" => "2021-05-20T03:26:16.000000Z"
    "has_disliked" => true
  ],
  [
    "id" => 2
    "title" => "Post title2"
    "created_at" => "2021-05-20T03:26:16.000000Z"
    "updated_at" => "2021-05-20T03:26:16.000000Z"
    "has_disliked" => fasle
  ],
  [
    "id" => 3
    "title" => "Post title3"
    "created_at" => "2021-05-20T03:26:16.000000Z"
    "updated_at" => "2021-05-20T03:26:16.000000Z"
    "has_disliked" => true
  ],
]
```

#### For pagination

[](#for-pagination)

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

$user->attachLikeStatus($posts);

$posts = Post::paginate(20);

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

Troubleshooting
---------------

[](#troubleshooting)

If you encounter any issues or need help, please refer to the [Troubleshooting section](#troubleshooting) in the documentation for assistance.

Contributing
------------

[](#contributing)

Contributions are welcome! If you'd like to contribute to

the Laravel Like System Package, please follow the guidelines in the [Contributing section](#contributing) of the documentation.

License
-------

[](#license)

The Laravel Like System Package is open-source software licensed under the [MIT license](LICENSE).

---

This concludes the documentation for the Laravel Like System Package. For more information and detailed usage instructions, please refer to the sections above. If you have any questions or need further assistance, don't hesitate to reach out to the package author or community for support.

We hope you find the Laravel Like System Package a valuable addition to your Laravel projects! Happy coding!

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.7% 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 ~6 days

Total

6

Last Release

975d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/580398aa8b1d0d1cb061e920dbc65c479e9a2caf16365f1f442e5922977797b1?d=identicon)[EslamFaroug](/maintainers/EslamFaroug)

---

Top Contributors

[![clooudbase](https://avatars.githubusercontent.com/u/101792285?v=4)](https://github.com/clooudbase "clooudbase (6 commits)")[![EslamFaroug](https://avatars.githubusercontent.com/u/63267476?v=4)](https://github.com/EslamFaroug "EslamFaroug (1 commits)")

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[wireui/wireui

TallStack components

1.8k1.3M16](/packages/wireui-wireui)[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4195.3M84](/packages/livewire-volt)[ramonrietdijk/livewire-tables

Dynamic tables for models with Laravel Livewire

21147.4k](/packages/ramonrietdijk-livewire-tables)

PHPackages © 2026

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