puzzle9 / laravel-user-blockable
Laravel user block system
v1.1.0
2021-03-31 06:21 UTC
Requires
- php: >=7.0
- illuminate/database: >=5.4
- illuminate/support: >=5.4
- nesbot/carbon: >=2.0
Requires (Dev)
- phpunit/phpunit: ~5.7
This package is auto-updated.
Last update: 2024-10-29 06:46:53 UTC
README
This package helps you to add user block system to your project.
- So simply and easy.
- Use "ON DELETE CASCADE" in block relationships table.
Caution
- Support Laravel 8.x~
- Required php >=7.0
Installation
First, pull in the package through Composer.
Run composer require puzzle9/laravel-user-blockable
Publish the config file. (blockable.php)
$ php artisan vendor:publish --provider="Hareku\LaravelBlockable\BlockableServiceProvider"
Finally, use Blockable trait in User model.
use Hareku\LaravelBlockable\Traits\Blockable; class User extends Model { use Blockable; }
Usage
Block a user or users
$user->block(1); $user->block([1,2,3,4]);
Add blockers
$user->addBlockers(1); $user->addBlockers([1,2,3,4]);
Unblock a user or users
$user->unblock(1); $user->unblock([1,2,3,4]);
Get blocker users / blocked by users
// blocker users $user->blockerUsers()->get(); // Get blocker user models. $user->blockerRelationships()->get(); // Get blocker relationship models. // blocked by users $user->blockingUsers()->get(); $user->blockingRelationships()->get();
Check if it is blocking
$user->isBlocking(1); $user->isBlocking([1,2,3,4]);
Check if it is being blocked
$user->isBlockedBy(1); $user->isBlockedBy([1,2,3,4]);
Check if it is mutual block
$user->isMutualBlock(1); $user->isMutualBlock([1,2,3,4]);
Get blocker/blocked IDs
$user->block([1,2,3]); $user->blockerIds(); // [1,2,3] $user->blockingIds();
Reject user ids
$user->blockerUsers()->pluck('id')->all(); // [1,2,3] $user->rejectNotBlocker([1,2,3,4,5]); // [1,2,3]
$user->block([1,2,3]); $user->rejectNotBlocking([1,2,3,4,5]); // [1,2,3]
License
MIT
Author
hareku (hareku908@gmail.com)
Fork
barisdemirhan (barisdemirhn@gmail.com)
其他
讲真
目前我对这函数 按照这个被
字关系 理解不清楚
就是类似于
a拉黑了b b被a拉黑了