liquidstyle / laravel-likeable
Laravel Eloquent模型特性,用于轻松实现“点赞”或“收藏”以及“愿望清单”功能。
v2.2.6
2018-12-29 04:32 UTC
Requires
- php: >=5.5.0
- illuminate/database: >=5.0
- illuminate/support: >=5.0
Requires (Dev)
- mockery/mockery: ~0.9
- orchestra/testbench: ~3.0
- phpunit/phpunit: ~4.0
README
!!! 不稳定 - 不要使用 !!!
Laravel Likeable 插件
!!! 不稳定 - 不要使用 !!! Laravel Eloquent模型特性,用于轻松实现“点赞”或“收藏”或“记住”功能。
Composer 安装(适用于 Laravel 5)
composer require liquidstyle/laravel-likeable "~2.0"
安装并运行迁移
php artisan vendor:publish --provider="Liquidstyle\Likeable\LikeableServiceProvider" --tag=migrations
php artisan migrate
设置您的模型
class Item extends \Illuminate\Database\Eloquent\Model { use \Liquidstyle\Likeable\LikeableTrait; use \Liquidstyle\Likeable\FavoriteableTrait; use \Liquidstyle\Likeable\WishlistableTrait; }
LIKE 示例用法
$item->like(); // like the item for current user $item->like($myUserId); // pass in your own user id $item->like(0); // just add likes to the count, and don't track by user $item->unlike(); // remove like from the item $item->unlike($myUserId); // pass in your own user id $item->unlike(0); // remove likes from the count -- does not check for user $item->likeCount; // get count of likes $item->likes; // Iterable Illuminate\Database\Eloquent\Collection of existing likes $item->liked(); // check if currently logged in user liked the item $item->liked($myUserId); Item::whereLikedBy($myUserId) // find only items where user liked them ->with('likeCounter') // highly suggested to allow eager load ->get();
FAVORITE 示例用法
$item->favorite(); // favorite the item for current user $item->favorite($myUserId); // pass in your own user id $item->favorite(0); // just add favorites to the count, and don't track by user $item->unfavorite(); // remove favorite from the item $item->unfavorite($myUserId); // pass in your own user id $item->unfavorite(0); // remove favorites from the count -- does not check for user $item->favoriteCount; // get count of favorites $item->favorites; // Iterable Illuminate\Database\Eloquent\Collection of existing favorites $item->favorited(); // check if currently logged in user favorited the item $item->favorited($myUserId); Item::whereFavoritedBy($myUserId) // find only items where user favorited them ->with('favoriteCounter') // highly suggested to allow eager load ->get();
WISHLISTED 示例用法
$item->wishlist(); // wishlist the item for current user $item->wishlist($myUserId); // pass in your own user id $item->wishlist(0); // just add wishlists to the count, and don't track by user $item->unwishlist(); // remove wishlist from the item $item->unwishlist($myUserId); // pass in your own user id $item->unwishlist(0); // remove wishlists from the count -- does not check for user $item->wishlistCount; // get count of wishlists $item->wishlist; // Iterable Illuminate\Database\Eloquent\Collection of existing wishlists $item->wishlisted(); // check if currently logged in user wishlisted the item $item->wishlisted($myUserId); Item::whereWishlistedBy($myUserId) // find only items where user wishlisted them ->with('wishlistCounter') // highly suggested to allow eager load ->get();
致谢
- Robert Conner - http://smartersoftware.net(原始开发者)
- Jaye E. Miller - http://github.com/liquidstyle