This package implements the likes/dislikes system in the laravel framework.
You can install the package via composer:
- Install the package via Composer
composer require manzadey/laravel-like
- Publish the database from the command line:
php artisan vendor:publish --provider="Manzadey\LaravelLike\LikeServiceProvider"
- Migrate the database from the command line:
php artisan migrate
Publishing the config file is optional:
php artisan vendor:publish --provider="Manzadey\LaravelLike\LikeServiceProvider" --tag="config"
Your User model should import the Likeability
trait, LikeabilityContract
implements interface and use it, that trait allows the user to like the models.
(see an example below):
use Manzadey\LaravelLike\Traits\Likeability;
use Manzadey\LaravelLike\Contracts\LikeabilityContract;
class User extends Authenticatable implements LikeabilityContract;
{
use Likeability;
}
Your models should import the Likeable
trait, LikeableContract
implements interface and use it, that trait has the methods that you'll use to allow the model be likeable.
In all the examples I will use the Post model as the model that is 'Likeable', that's for example proposes only.
(see an example below):
use Manzadey\LaravelLike\Traits\Likeable;
use Manzadey\LaravelLike\Contracts\LikeableContract;
class Post extends Model implements LikeableContract
{
use Likeable;
}
That's it ... your model is now "likeable"! Now the User can favorite models that have the favoriteable trait.
$article = \App\Models\Article::first();
$user = \App\Models\User::first();
$article->like($user); // Add the current model to like of the specified user
$article->dislike($user); // Add the current model to dislike of the specified user
$article->toggleLike($user); // The switch of the likes of the specified user
$article->removeLikeable($user); // Delete the current module from the likes of the specified user
$article->isLike($user); // Check the current model whether it is a likes of the specified user
$article->isDislike($user); // Check the current model whether it is a likes of the specified user
You can also use these methods as a `Likeability' model.
$article = \App\Models\Article::first();
$user = \App\Models\User::first();
$article->isLike($user);
$article->isDislike($user);
You can also use these methods as a `Likeability' model.
$article = \App\Models\Article::first();
$article->isLikes();
$article->isDislikes();
$article = \App\Models\Article::first();
$user = \App\Models\User::first();
$article->likeBy();
$article->dislikeBy();
$article = \App\Models\Article::first();
$user = \App\Models\User::first();
$user->getLike();
$user->getDisike();
// With usage models
$user->getLike([\App\Models\Article::class]);
$user->getDisike([\App\Models\Article::class]);
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email andrey.manzadey@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the Laravel Package Boilerplate.