This is a like management package for Laravel that you can use in your projects.
Run the following command to pull in the latest version:
composer require jobmetric/laravel-like
This package evolves every day under constant development and integrates a diverse set of features. It is a must-have asset for Laravel enthusiasts and provides a seamless way to coordinate your projects with like and dislike base models.
In this package, you can use it seamlessly with any model that requires likes and dislikes.
Now let's move on to the main function.
php artisan migrate
Meet the HasLike
class, meticulously designed for integration into your model. This class automates essential tasks, ensuring a streamlined process for:
In the first step, you need to connect this class to your main model.
use JobMetric\Like\HasLike;
class Post extends Model
{
use HasLike;
}
You can now use the HasLike
class for your model. The following example shows how to create a new post with a like:
$post = Post::create([
'status' => 'published',
]);
$user_id = 1;
$post->likeIt($user_id, $type = true);
The
likeIt
function is used to like the post. The first parameter is the user id, and the second parameter is the type of like. If you want to dislike, you can set it tofalse
.
like has one relationship
like has many relationships
scope locale for select like relationship
scope locale for select disLike relationship
scope locale for select likes relationship
scope locale for select disLikes relationship
This function is very important and is used to store user's likes and dislikes.
$post->likeIt($user_id, $type = true);
The
likeIt
function is used to like the post. The first parameter is the user id, and the second parameter is the type of like. If you want to dislike, you can set it tofalse
. user_id: user id type: like or dislike
get count of likes
get count of dislikes
This function helps to see the number of likes and dislikes of each object and loads it in the desired model.
$post->loadLikeDislikeCount();
load like or disLike after model loaded
The
loadLikeDislike
function is used to load the likes and dislikes of the object after the model is loaded.
load likes or dislikes after model loaded
The
loadLikesDislikes
function is used to load the likes and dislikes of the object after the model is loaded.
is liked or disliked by user
$type = $post->isLikedDislikedBy($user_id);
if(\JobMetric\Like\Enums\LikeTypeEnum::LIKE == $type) {
// liked
} else if(\JobMetric\Like\Enums\LikeTypeEnum::DISLIKE == $type) {
// disliked
} else {
// not liked or disliked
}
forget like or dislike
$post->forgetLike($user_id);
forget likes or dislikes
$post->forgetLikes();
Thank you for considering contributing to the Laravel Like! The contribution guide can be found in the CONTRIBUTING.md.
The MIT License (MIT). Please see License File for more information.