This package is abandoned and no longer maintained. Development moved to Laravel Love package!
If you already have installed version of Laravel Likeable you can use Laravel Love Migration Guide.
Laravel Likeable simplify management of Eloquent model's likes & dislikes. Make any model likeable & dislikeable in a minutes!
- Features
 - Installation
 - Usage
 - Extending
 - Change log
 - Contributing
 - Testing
 - Security
 - Contributors
 - Alternatives
 - License
 - About CyberCog
 
- 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,undislikemethods. - Following PHP Standard Recommendations:
 - Covered with unit tests.
 
First, pull in the package through Composer.
$ composer require cybercog/laravel-likeableIf you are using Laravel 5.5 you can skip register package part.
Include the service provider within app/config/app.php.
'providers' => [
    Cog\Likeable\Providers\LikeableServiceProvider::class,
],At last you need to publish and run database migrations.
$ php artisan vendor:publish --provider="Cog\Likeable\Providers\LikeableServiceProvider" --tag=migrations
$ php artisan migrateUse 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;
}$article->like(); // current user
$article->like($user->id);$article->unlike(); // current user
$article->unlike($user->id);$article->likeToggle(); // current user
$article->likeToggle($user->id);$article->likesCount;$article->likesCounter;$article->likes();$article->likes;$article->liked; // current user
$article->liked(); // current user
$article->liked($user->id);Checks in eager loaded relations likes & likesAndDislikes first.
$article->collectLikers();$article->removeLikes();$article->dislike(); // current user
$article->dislike($user->id);$article->undislike(); // current user
$article->undislike($user->id);$article->dislikeToggle(); // current user
$article->dislikeToggle($user->id);$article->dislikesCount;$article->dislikesCounter;$article->dislikes();$article->dislikes;$article->disliked; // current user
$article->disliked(); // current user
$article->disliked($user->id);Checks in eager loaded relations dislikes & likesAndDislikes first.
$article->collectDislikers();$article->removeDislikes();$article->likesDiffDislikesCount;$article->likesAndDislikes();$article->likesAndDislikes;Article::whereLikedBy($user->id)
    ->with('likesCounter') // Allow eager load (optional)
    ->get();Article::whereDislikedBy($user->id)
    ->with('dislikesCounter') // Allow eager load (optional)
    ->get();$sortedArticles = Article::orderByLikesCount()->get();
$sortedArticles = Article::orderByLikesCount('asc')->get();Uses desc as default order direction.
$sortedArticles = Article::orderByDislikesCount()->get();
$sortedArticles = Article::orderByDislikesCount('asc')->get();Uses desc as default order direction.
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.
$ likeable:recount$ likeable:recount --model="article"$ likeable:recount --model="App\Models\Article"$ likeable:recount --type="like"$ likeable:recount --model="article" --type="like"$ likeable:recount --model="App\Models\Article" --type="like"$ likeable:recount --type="dislike"$ likeable:recount --model="article" --type="dislike"$ likeable:recount --model="App\Models\Article" --type="dislike"You can override core classes of package with your own implementations:
Models\LikeModels\LikeCounterServices\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 in your application service providers.
$this->app->bind(
    \Cog\Likeable\Contracts\Like::class,
    \App\Models\CustomLike::class
);$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);Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
You can run the tests with:
$ vendor/bin/phpunitIf you discover any security related issues, please email open@cybercog.su instead of using the issue tracker.
Anton Komarev  | 
Kevin Olson  | 
|---|
Laravel Likeable contributors list
- cybercog/laravel-love
 - rtconner/laravel-likeable
 - faustbrian/laravel-likeable
 - sukohi/evaluation
 - zvermafia/lavoter
 
Feel free to add more alternatives as Pull Request.
Laravel Likeablepackage is open-sourced software licensed under the MIT license by Anton Komarev.
CyberCog is a Social Unity of enthusiasts. Research best solutions in product & software development is our passion.

