Make Laravel Eloquent models Likeable using UUIDs.
gorankrgovic/laravel-likeable is a Laravel package for make laravel eloquent models likeable using uuids..
It currently has 2 GitHub stars and 64 downloads on Packagist (latest version v0.0.4).
Install it with composer require gorankrgovic/laravel-likeable.
Discover more Laravel packages by gorankrgovic
or browse all Laravel packages to compare alternatives.
Last updated
This package is basically a simplified fork of a Laravel Love package with only using LIKE and UNLIKE capability. "Laravel Love" have more capabilities such as both "LIKE" and "DISLIKE" functionality.
Also, worth noting that this package utilizes usage of UUID's instead of integer ID's. And the "Likeable" and "Liker" models needs to utilize UUIDs as well. If you are not using UUID's please use the cybercog/laravel-likeable, cybercog/laravel-love or any of the alternatives listed below.
For the UUID generation this package uses Ramsey UUID.
LikeableService.golike:recount {model?} to re-fetch like counters.like, unlike methods.First, pull in the package through Composer.
$ composer require gorankrgovic/laravel-likeable
At last you need to publish and run database migrations.
$ php artisan migrate
If you want to make changes in migrations, publish them to your application first.
$ php artisan vendor:publish --provider="Gox\Laravel\Likeable\Providers\LikeableServiceProvider" --tag=migrations
Use Gox\Contracts\Likeble\Liker\Models\Liker contract in model which will get likes
behavior and implement it or just use Gox\Laravel\Likeable\Liker\Models\Traits\Liker trait.
use Gox\Contracts\Likeable\Liker\Models\Liker as LikerContract;
use Gox\Laravel\Likeable\Liker\Models\Traits\Liker;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable implements LikerContract
{
use Liker;
}
Use Gox\Contracts\Likeable\Likeable\Models\Likeable contract in model which will get likes
behavior and implement it or just use Gox\Laravel\Likeable\Likeable\Models\Traits\Likeable trait.
use Gox\Contracts\Likeable\Likeable\Models\Likeable as LikeableContract;
use Gox\Laravel\Likeable\Likeable\Models\Traits\Likeable;
use Illuminate\Database\Eloquent\Model;
class Article extends Model implements LikeableContract
{
use Likeable;
}
$user->like($article);
$article->likeBy(); // current user
$article->likeBy($user->id);
$user->unlike($article);
$article->unlikeBy(); // current user
$article->unlikeBy($user->id);
$article->likesCount;
$article->likesCounter;
$article->likes();
Illuminate\Database\Eloquent\Collection of existing model likes$article->likes;
$user->hasLiked($article);
$article->liked; // current user
$article->isLikedBy(); // current user
$article->isLikedBy($user->id);
Checks in eager loaded relations likes first.
$article->collectLikers();
$article->removeLikes();
Article::whereLikedBy($user->id)
->with('likesCounter') // Allow eager load (optional)
->get();
$sortedArticles = Article::orderByLikesCount()->get();
$sortedArticles = Article::orderByLikesCount('asc')->get();
Uses desc as default order direction.
On each like added \Gox\Laravel\Subscribe\Subscribeable\Events\LikeableWasLiked event is fired.
On each like removed \Gox\Laravel\Subscribe\Subscribeable\Events\LikeableWasUnliked event is fired.
$ golike:recount
$ golike:recount --model="article"
$ golike:recount --model="App\Models\Article"
If you discover any security related issues, please email me instead of using the issue tracker.
Laravel Likeable package is open-sourced software licensed under the MIT license by Goran Krgovic.Laravel Love package is open-sourced software licensed under the MIT license by Anton Komarev.