racashmoney / laravel-blockable
Laravel Eloquent 模型特性,允许轻松实现“阻止”或“忽略”功能。
2.0.3
2016-08-15 22:41 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 Eloquent 模型特性,允许轻松实现“阻止”或“忽略”功能。
Composer 安装(适用于 Laravel 5)
composer require racashmoney/laravel-blockable "~2.0"
安装并运行迁移
'providers' => [ \Racashmoney\Blockable\BlockableServiceProvider::class, ],
php artisan vendor:publish --provider="Racashmoney\Blockable\BlockableServiceProvider" --tag=migrations
php artisan migrate
设置您的模型
class Article extends \Illuminate\Database\Eloquent\Model { use \Racashmoney\Blockable\Blockable; }
示例用法
$article->block(); // block the article for current user $article->block($myUserId); // pass in your own user id $article->block(0); // just add blocks to the count, and don't track by user $article->unblock(); // remove block from the article $article->unblock($myUserId); // pass in your own user id $article->unblock(0); // remove blocks from the count -- does not check for user $article->blockCount; // get count of blocks $article->blocks; // Iterable Illuminate\Database\Eloquent\Collection of existing blocks $article->blocked(); // check if currently logged in user blocked the article $article->blocked($myUserId); Article::whereBlockedBy($myUserId) // find only articles where user blocked them ->with('blockCounter') // highly suggested to allow eager load ->get();
致谢
- Robert Conner - http://smartersoftware.net