miragepresent/likeable

快速点赞支持

v0.1.0 2018-01-18 08:30 UTC

This package is auto-updated.

Last update: 2024-09-29 05:27:40 UTC


README

安装

运行 composer require miragepresent/likeable;

然后 php artisan migrate

使用方法

只需在您的模型中使用 Likeable 特性

namespace App;
 
use Illuminate\Database\Eloquent\Model;
use MiragePresent\Likeable\Likeable;
 
class Photo extends Model {
 
    use Likeable;
 
}

现在您可以在模型中使用 like()dislike()toggleLike() 方法为授权用户添加/移除点赞。

示例


/** @var \App\Photo $photo */
$photo = Photo::find(1); 
 
// Add like to the photo
$photo->like();
 
var_dump($photo->is_liked); \\ true, 1
 
echo $photo->count_likes. ' user(s) liked this photo';
echo $photo->likedBy->ipmlode('name', ',') . ' liked this photo';