implementation likeable service for laravel project

dev-main 2024-01-17 06:13 UTC

This package is auto-updated.

Last update: 2024-09-17 07:42:34 UTC


README

for laravel 8.x or above

Installation

Use the package manager composer to install Likeable.

composer require peyman-manteali/likeable

Run the migrations

php artisan migrate

Usage

class Post extends Model
{
    use PeymanManteali\Likeable
}

Methods

    $post->likes(); 
    // Collection (Illuminate\Database\Eloquent\Collection)
    // of existing likes and dislikes for this post.

    $post->like(); // like the post for current user.
    $post->dislike(); // dislike the post for current user.
    
    $post->removeLike(); // remove like from this post for current user.
    $post->removeDislike(); // remove dislike from this post for current user.
    
    $post->isLiked(); // check if current user liked the post.
    $post->isDisliked(); // check if current user disliked the post.
    
    $post->likeCount; // get Total count of likes.
    $post->dislikeCount; // get Total count of dislikes.
    
    Post::likedBy($userId) // find only posts where user liked them.
    Post::dislikedBy($userId) // find only posts where user disliked them.
    

License [MIT](https://choosealicense.com/licenses/mit/)

Developed by Peyman Manteali

payman.manteali@gmail.com