shubhang / laravel-dislikeable
为 Laravel Eloquent 模型提供 trait,以实现“不喜欢”功能的简易实现。
1.0
2017-01-09 08:37 UTC
Requires
- php: >=5.3.0
- illuminate/database: ~5.0
- illuminate/support: ~5.0
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-09-28 19:58:22 UTC
README
为 Laravel Eloquent 模型提供 trait,以实现“不喜欢”功能的简易实现。
Composer 安装(适用于 Laravel 5)
composer require shubhang-arora/laravel-dislikeable "~1.0"
安装并运行迁移
'providers' => array( Shubhang\DisLikeable\DisLikeableServiceProvider::class, );
php artisan vendor:publish --provider="Shubhang\DisLikeable\DisLikeableServiceProvider"
php artisan migrate
设置你的模型
class Article extends \Illuminate\Database\Eloquent\Model {
use Shubhang\DisLikeable\DisLikeableTrait;
}
示例用法
$article->dislike(); // dislike the article for current user
$article->dislike($myUserId); // pass in your own user id
$article->dislike(0); // just add dislikes to the count, and don't track by user
$article->undislike(); // remove dislike from the article
$article->undislike($myUserId); // pass in your own user id
$article->undislike(0); // remove dislikes from the count -- does not check for user
$article->dislikeCount; // get count of dislikes
$article->dislikes; // Iterable Illuminate\Database\Eloquent\Collection of existing dislikes
$article->disliked(); // check if currently logged in user disliked the article
$article->disliked($myUserId);
Article::whereDisLiked($myUserId) // find only articles where user disliked them
->with('dislikeCounter') // highly suggested to allow eager load
->get();
致谢
- Shubhang Arora