inpin/lara-like
Composer 安装命令:
composer require inpin/lara-like
包简介
Add Likeable trait to Laravel Eloquent models
关键字:
README 文档
README
Important note: this product is forked and edited from base laravel-likeable package.
Trait for Laravel Eloquent models to allow easy implementation of a "like" or "favorite" or "remember" or what ever you want features.
Composer Install (for Laravel 5.5 and above)
composer require inpin/lara-like
Install and then run the migrations
'providers' => [ \Inpin\LaraLike\LaraLikeServiceProvider::class, ],
php artisan vendor:publish --provider="Inpin\LaraLike\LaraLikeServiceProvider" --tag=migrations
php artisan migrate
Setup your models
class Book extends \Illuminate\Database\Eloquent\Model { use Inpin\LaraLike\Likeable; }
Sample Usage
$book->like(); // like the book for current user $book->like($user); // pass in your own user $book->like(0); // just add likes to the count, and don't track by user $book->like('api'); // like the book for current user with guard 'api' $book->like(null, 'bookmark') // add book for current user to bookmarks $book->like($user, 'bookmark') // pass user and type $book->unlike(); // remove like from the book $book->unlike($user); // pass in your own user id $book->unlike(0); // remove likes from the count -- does not check for user $book->unlike('api'); // remove like from book for current user with guard 'api' $book->unlike(null, 'bookmark') // remove current book from current user bookmarks $book->unlike($user, 'bookmark') // pass user and type $book->likes; // Iterable Illuminate\Database\Eloquent\Collection of existing likes $book->likes()->where('type', 'bookmark') $book->liked(); // check if currently logged in user liked the book $book->liked($myUserId); $book->likeCount($type); // determine number of likes for given $type (default type is 'like') Article::whereLikedBy($myUserId) // find only books where user liked them ->with('likeCounter') // highly suggested to allow eager load ->get();
note: default type is 'like'.
Credits
- Mohammad Nourinik - http://inpinapp.com
统计信息
- 总下载量: 938
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-10-18