timgavin/laravel-block
用户可以阻止另一个用户
1.1.10
2024-04-27 15:34 UTC
Requires (Dev)
- orchestra/testbench: ~7
- phpunit/phpunit: ~9.0
README
一个简单的用于阻止用户的 Laravel 扩展包。
要求
- Laravel 9 或更高版本。
- Laravel
User
模型。
安装
通过 Composer
$ composer require timgavin/laravel-block
将 Laravel Block 导入 User 模型并添加特性。
namespace App\Models; use TimGavin\LaravelBlock\LaravelBlock; class User extends Authenticatable { use LaravelBlock; }
然后运行迁移。
php artisan migrate
用法
阻止一个用户。
auth()->user()->block($user);
解除阻止一个用户。
auth()->user()->unblock($user);
检查一个用户是否阻止了另一个用户。
@if (auth()->user()->isBlocking($user)) You are blocking this user. @endif
检查一个用户是否被另一个用户阻止。
@if (auth()->user()->isBlockedBy($user)) This user is blocking you. @endif
返回被一个用户阻止的用户。
auth()->user()->getBlocking();
返回阻止一个用户的用户。
auth()->user()->getBlockers();
返回一个数组,包含被一个用户阻止的用户 ID。
auth()->user()->getBlockingIds();
返回一个数组,包含阻止一个用户的用户 ID。
auth()->user()->getBlockersIds();
返回一个数组,包含被一个用户阻止的用户 ID,以及阻止该用户的用户 ID。
auth()->user()->getBlockingAndBlockersIds()
缓存被一个用户阻止的用户 ID。默认为 1 天。
// 1 day auth()->user()->cacheBlocking(); // 1 hour auth()->user()->cacheBlocking(3600); // 1 month auth()->user()->cacheBlocking(Carbon::addMonth());
返回一个数组,包含被一个用户阻止的用户 ID。
auth()->user()->getBlockingCache();
缓存阻止一个用户的用户 ID。默认为 1 天。
auth()->user()->cacheBlockers();
返回一个数组,包含阻止一个用户的用户 ID。
auth()->user()->getBlockersCache();
清除阻止缓存
auth()->user()->clearBlockingCache();
清除阻止者缓存
auth()->user()->clearBlockersCache();
变更日志
请查看 变更日志 以获取最近更改的更多信息。
测试
$ composer test
安全
如果您发现任何安全相关的问题,请发送电子邮件至 tim@timgavin.name,而不是使用问题跟踪器。
许可证
MIT。请参阅 许可证文件 以获取更多信息。