PHPackages                             itbm/laravel-likeable - 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. [Database &amp; ORM](/categories/database)
4. /
5. itbm/laravel-likeable

ActiveLibrary[Database &amp; ORM](/categories/database)

itbm/laravel-likeable
=====================

Make Laravel Eloquent models Likeable &amp; Dislikeable in a minutes!

3.4.0(3y ago)053MITPHPPHP ^7.0|^8.0

Since Sep 6Pushed 3y agoCompare

[ Source](https://github.com/itbm/laravel-likeable)[ Packagist](https://packagist.org/packages/itbm/laravel-likeable)[ Docs](https://github.com/cybercog/laravel-likeable)[ RSS](/packages/itbm-laravel-likeable/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (6)Versions (20)Used By (0)

Laravel Likeable
================

[](#laravel-likeable)

[![cog-laravel-likeable](https://user-images.githubusercontent.com/1849174/28696355-c4a06a96-733d-11e7-8cc5-af5d60bf5e20.png)](https://user-images.githubusercontent.com/1849174/28696355-c4a06a96-733d-11e7-8cc5-af5d60bf5e20.png)

[![Releases](https://camo.githubusercontent.com/326e36f86b0bee1e82831ee04a90e15bc81ea2ec9c6b93c0c2b67f171c9fb8d8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6974626d2f6c61726176656c2d6c696b6561626c652e7376673f7374796c653d666c61742d737175617265)](https://github.com/itbm/laravel-likeable/releases)[![License](https://camo.githubusercontent.com/ea33124c0d924d6628e0e1a350e22c62a2ba64a49da75a843cbab435f9032377/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6974626d2f6c61726176656c2d6c696b6561626c652e7376673f7374796c653d666c61742d737175617265)](https://github.com/itbm/laravel-likeable/blob/master/LICENSE)

Attention
---------

[](#attention)

**This package is abandoned and no longer maintained. Development moved to [Laravel Love package](https://github.com/cybercog/laravel-love)!**

If you already have installed version of Laravel Likeable you can use [Laravel Love Migration Guide](https://github.com/cybercog/laravel-love/blob/master/UPGRADING.md#from-v3-to-v4).

Introduction
------------

[](#introduction)

Laravel Likeable simplify management of Eloquent model's likes &amp; dislikes. Make any model `likeable` &amp; `dislikeable` in a minutes!

Contents
--------

[](#contents)

- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
    - [Prepare likeable model](#prepare-likeable-model)
    - [Available methods](#available-methods)
    - [Scopes](#scopes)
    - [Events](#events)
    - [Console commands](#console-commands)
- [Extending](#extending)
- [Change log](#change-log)
- [Contributing](#contributing)
- [Testing](#testing)
- [Security](#security)
- [Contributors](#contributors)
- [Alternatives](#alternatives)
- [License](#license)
- [About CyberCog](#about-cybercog)

Features
--------

[](#features)

- Designed to work with Laravel Eloquent models.
- Using contracts to keep high customization capabilities.
- Using traits to get functionality out of the box.
- Most part of the the logic is handled by the `LikeableService`.
- Has Artisan command `likeable:recount {model?} {type?}` to re-fetch likes counters.
- Likeable model can has Likes and Dislikes.
- Likes and Dislikes for one model are mutually exclusive.
- Get Likeable models ordered by likes count.
- Events for `like`, `unlike`, `dislike`, `undislike` methods.
- Following PHP Standard Recommendations:
    - [PSR-1 (Basic Coding Standard)](http://www.php-fig.org/psr/psr-1/).
    - [PSR-2 (Coding Style Guide)](http://www.php-fig.org/psr/psr-2/).
    - [PSR-4 (Autoloading Standard)](http://www.php-fig.org/psr/psr-4/).
- Covered with unit tests.

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

[](#installation)

First, pull in the package through Composer.

```
$ composer require itbm/laravel-likeable
```

**If you are using Laravel 5.5 you can skip register package part.**

#### Register package on Laravel 5.4 and lower

[](#register-package-on-laravel-54-and-lower)

Include the service provider within `app/config/app.php`.

```
'providers' => [
    Cog\Likeable\Providers\LikeableServiceProvider::class,
],
```

#### Perform Database Migration

[](#perform-database-migration)

At last you need to publish and run database migrations.

```
$ php artisan vendor:publish --provider="Cog\Likeable\Providers\LikeableServiceProvider" --tag=migrations
$ php artisan migrate
```

Usage
-----

[](#usage)

### Prepare likeable model

[](#prepare-likeable-model)

Use `Likeable` contract in model which will get likes behavior and implement it or just use `Likeable` trait.

```
use Cog\Likeable\Contracts\Likeable as LikeableContract;
use Cog\Likeable\Traits\Likeable;
use Illuminate\Database\Eloquent\Model;

class Article extends Model implements LikeableContract
{
    use Likeable;
}
```

### Available methods

[](#available-methods)

#### Likes

[](#likes)

##### Like model

[](#like-model)

```
$article->like(); // current user
$article->like($user->id);
```

##### Remove like mark from model

[](#remove-like-mark-from-model)

```
$article->unlike(); // current user
$article->unlike($user->id);
```

##### Toggle like mark of model

[](#toggle-like-mark-of-model)

```
$article->likeToggle(); // current user
$article->likeToggle($user->id);
```

##### Get model likes count

[](#get-model-likes-count)

```
$article->likesCount;
```

##### Get model likes counter

[](#get-model-likes-counter)

```
$article->likesCounter;
```

##### Get likes relation

[](#get-likes-relation)

```
$article->likes();
```

##### Get iterable `Illuminate\Database\Eloquent\Collection` of existing model likes

[](#get-iterable-illuminatedatabaseeloquentcollection-of-existing-model-likes)

```
$article->likes;
```

##### Boolean check if user liked model

[](#boolean-check-if-user-liked-model)

```
$article->liked; // current user
$article->liked(); // current user
$article->liked($user->id);
```

*Checks in eager loaded relations `likes` &amp; `likesAndDislikes` first.*

##### Get collection of users who liked model

[](#get-collection-of-users-who-liked-model)

```
$article->collectLikers();
```

##### Delete all likes for model

[](#delete-all-likes-for-model)

```
$article->removeLikes();
```

#### Dislikes

[](#dislikes)

##### Dislike model

[](#dislike-model)

```
$article->dislike(); // current user
$article->dislike($user->id);
```

##### Remove dislike mark from model

[](#remove-dislike-mark-from-model)

```
$article->undislike(); // current user
$article->undislike($user->id);
```

##### Toggle dislike mark of model

[](#toggle-dislike-mark-of-model)

```
$article->dislikeToggle(); // current user
$article->dislikeToggle($user->id);
```

##### Get model dislikes count

[](#get-model-dislikes-count)

```
$article->dislikesCount;
```

##### Get model dislikes counter

[](#get-model-dislikes-counter)

```
$article->dislikesCounter;
```

##### Get dislikes relation

[](#get-dislikes-relation)

```
$article->dislikes();
```

##### Get iterable `Illuminate\Database\Eloquent\Collection` of existing model dislikes

[](#get-iterable-illuminatedatabaseeloquentcollection-of-existing-model-dislikes)

```
$article->dislikes;
```

##### Boolean check if user disliked model

[](#boolean-check-if-user-disliked-model)

```
$article->disliked; // current user
$article->disliked(); // current user
$article->disliked($user->id);
```

*Checks in eager loaded relations `dislikes` &amp; `likesAndDislikes` first.*

##### Get collection of users who disliked model

[](#get-collection-of-users-who-disliked-model)

```
$article->collectDislikers();
```

##### Delete all dislikes for model

[](#delete-all-dislikes-for-model)

```
$article->removeDislikes();
```

#### Likes and Dislikes

[](#likes-and-dislikes)

##### Get difference between likes and dislikes

[](#get-difference-between-likes-and-dislikes)

```
$article->likesDiffDislikesCount;
```

##### Get likes and dislikes relation

[](#get-likes-and-dislikes-relation)

```
$article->likesAndDislikes();
```

##### Get iterable `Illuminate\Database\Eloquent\Collection` of existing model likes and dislikes

[](#get-iterable-illuminatedatabaseeloquentcollection-of-existing-model-likes-and-dislikes)

```
$article->likesAndDislikes;
```

### Scopes

[](#scopes)

##### Find all articles liked by user

[](#find-all-articles-liked-by-user)

```
Article::whereLikedBy($user->id)
    ->with('likesCounter') // Allow eager load (optional)
    ->get();
```

##### Find all articles disliked by user

[](#find-all-articles-disliked-by-user)

```
Article::whereDislikedBy($user->id)
    ->with('dislikesCounter') // Allow eager load (optional)
    ->get();
```

##### Fetch Likeable models by likes count

[](#fetch-likeable-models-by-likes-count)

```
$sortedArticles = Article::orderByLikesCount()->get();
$sortedArticles = Article::orderByLikesCount('asc')->get();
```

*Uses `desc` as default order direction.*

##### Fetch Likeable models by dislikes count

[](#fetch-likeable-models-by-dislikes-count)

```
$sortedArticles = Article::orderByDislikesCount()->get();
$sortedArticles = Article::orderByDislikesCount('asc')->get();
```

*Uses `desc` as default order direction.*

### Events

[](#events)

On each like added `\Cog\Likeable\Events\ModelWasLiked` event is fired.

On each like removed `\Cog\Likeable\Events\ModelWasUnliked` event is fired.

On each dislike added `\Cog\Likeable\Events\ModelWasDisliked` event is fired.

On each dislike removed `\Cog\Likeable\Events\ModelWasUndisliked` event is fired.

### Console commands

[](#console-commands)

##### Recount likes and dislikes of all model types

[](#recount-likes-and-dislikes-of-all-model-types)

```
$ likeable:recount
```

##### Recount likes and dislikes of concrete model type (using morph map alias)

[](#recount-likes-and-dislikes-of-concrete-model-type-using-morph-map-alias)

```
$ likeable:recount --model="article"
```

##### Recount likes and dislikes of concrete model type (using fully qualified class name)

[](#recount-likes-and-dislikes-of-concrete-model-type-using-fully-qualified-class-name)

```
$ likeable:recount --model="App\Models\Article"
```

##### Recount only likes of all model types

[](#recount-only-likes-of-all-model-types)

```
$ likeable:recount --type="like"
```

##### Recount only likes of concrete model type (using morph map alias)

[](#recount-only-likes-of-concrete-model-type-using-morph-map-alias)

```
$ likeable:recount --model="article" --type="like"
```

##### Recount only likes of concrete model type (using fully qualified class name)

[](#recount-only-likes-of-concrete-model-type-using-fully-qualified-class-name)

```
$ likeable:recount --model="App\Models\Article" --type="like"
```

##### Recount only dislikes of all model types

[](#recount-only-dislikes-of-all-model-types)

```
$ likeable:recount --type="dislike"
```

##### Recount only dislikes of concrete model type (using morph map alias)

[](#recount-only-dislikes-of-concrete-model-type-using-morph-map-alias)

```
$ likeable:recount --model="article" --type="dislike"
```

##### Recount only dislikes of concrete model type (using fully qualified class name)

[](#recount-only-dislikes-of-concrete-model-type-using-fully-qualified-class-name)

```
$ likeable:recount --model="App\Models\Article" --type="dislike"
```

Extending
---------

[](#extending)

You can override core classes of package with your own implementations:

- `Models\Like`
- `Models\LikeCounter`
- `Services\LikeableService`

*Note: Don't forget that all custom models must implement original models interfaces.*

To make it you should use container [binding interfaces to implementations](https://laravel.com/docs/master/container#binding-interfaces-to-implementations) in your application service providers.

##### Use model class own implementation

[](#use-model-class-own-implementation)

```
$this->app->bind(
    \Cog\Likeable\Contracts\Like::class,
    \App\Models\CustomLike::class
);
```

##### Use service class own implementation

[](#use-service-class-own-implementation)

```
$this->app->singleton(
    \Cog\Likeable\Contracts\LikeableService::class,
    \App\Services\CustomService::class
);
```

After that your `CustomLike` and `CustomService` classes will be instantiable with helper method `app()`.

```
$model = app(\Cog\Likeable\Contracts\Like::class);
$service = app(\Cog\Likeable\Contracts\LikeableService::class);
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Testing
-------

[](#testing)

You can run the tests with:

```
$ vendor/bin/phpunit
```

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Contributors
------------

[](#contributors)

[![@antonkomarev](https://avatars.githubusercontent.com/u/1849174?s=110)
Anton Komarev](https://github.com/antonkomarev)[![@acidjazz](https://avatars.githubusercontent.com/u/967369?s=110)
Kevin Olson](https://github.com/acidjazz)[Laravel Likeable contributors list](../../contributors)

Alternatives
------------

[](#alternatives)

- [cybercog/laravel-love](https://github.com/cybercog/laravel-love)
- [rtconner/laravel-likeable](https://github.com/rtconner/laravel-likeable)
- [faustbrian/laravel-likeable](https://github.com/faustbrian/Laravel-Likeable)
- [sukohi/evaluation](https://github.com/SUKOHI/Evaluation)
- [zvermafia/lavoter](https://github.com/zvermafia/lavoter)

*Feel free to add more alternatives as Pull Request.*

License
-------

[](#license)

- `Laravel Likeable` package is open-sourced software licensed under the [MIT license](LICENSE) by [Anton Komarev](https://komarev.com).

About CyberCog
--------------

[](#about-cybercog)

[CyberCog](https://cybercog.su) is a Social Unity of enthusiasts. Research best solutions in product &amp; software development is our passion.

- [Follow us on Twitter](https://twitter.com/cybercog)
- [Read our articles on Medium](https://medium.com/cybercog)

[![CyberCog](https://cloud.githubusercontent.com/assets/1849174/18418932/e9edb390-7860-11e6-8a43-aa3fad524664.png)](https://cybercog.su)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 87% 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 ~131 days

Recently: every ~502 days

Total

19

Last Release

1163d ago

Major Versions

1.1.2 → 2.0.02016-09-11

2.2.5 → 3.0.02017-08-26

PHP version history (2 changes)1.0.0PHP ^5.6|^7.0

3.4.0PHP ^7.0|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/4aa32e90d5b7888c1f665f71ddd622e73a85be5c3f2133a6bd14278bbf303d57?d=identicon)[itbm](/maintainers/itbm)

---

Top Contributors

[![antonkomarev](https://avatars.githubusercontent.com/u/1849174?v=4)](https://github.com/antonkomarev "antonkomarev (47 commits)")[![itbm](https://avatars.githubusercontent.com/u/22393016?v=4)](https://github.com/itbm "itbm (5 commits)")[![acidjazz](https://avatars.githubusercontent.com/u/967369?v=4)](https://github.com/acidjazz "acidjazz (1 commits)")[![squigg](https://avatars.githubusercontent.com/u/4279310?v=4)](https://github.com/squigg "squigg (1 commits)")

---

Tags

laraveleloquenttraitRatelikefavoritelikeablelikablefavouritecogRatingstarcybercogkudosdislikeemotion

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/itbm-laravel-likeable/health.svg)

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

###  Alternatives

[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[qirolab/laravel-reactions

Implement reactions (like, dislike, love, emotion etc) on Laravel Eloquent models.

19564.6k](/packages/qirolab-laravel-reactions)[rtconner/laravel-likeable

Trait for Laravel Eloquent models to allow easy implementation of a 'like' or 'favorite' or 'remember' feature.

394388.0k5](/packages/rtconner-laravel-likeable)[cybercog/laravel-ban

Laravel Ban simplify blocking and banning Eloquent models.

1.1k651.8k11](/packages/cybercog-laravel-ban)[multicaret/laravel-acquaintances

This light package, with no dependencies, gives Eloquent models the ability to manage friendships (with groups), verifications, and interactions such as: Likes, favorites, votes, subscribe, follow, ..etc. And it includes advanced rating system.

851266.9k2](/packages/multicaret-laravel-acquaintances)[rennokki/rating

Laravel Eloquent Rating allows you to assign ratings to any model.

19016.9k](/packages/rennokki-rating)

PHPackages © 2026

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