为laravel项目实现likeable服务

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

This package is auto-updated.

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


README

适用于laravel 8.x及以上版本

安装

使用包管理器 composer 安装Likeable。

composer require peyman-manteali/likeable

运行迁移

php artisan migrate

使用方法

class Post extends Model
{
    use PeymanManteali\Likeable
}

方法

    $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.
    

许可证 [MIT](https://choosealicense.com/licenses/mit/)

由Peyman Manteali开发

payman.manteali@gmail.com