laravel-interaction / block
User block/unblock behaviour for Laravel.
3.3.0
2024-03-18 14:48 UTC
Requires
- php: ^8.0
- illuminate/database: ^8.13 || ^9.0 || ^10.0 || ^11.0
- illuminate/support: ^8.0 || ^9.0 || ^10.0 || ^11.0
- laravel-interaction/support: ^1.0 || ^2.0 || ^3.0
Requires (Dev)
- mockery/mockery: ~1.3.3 || ^1.4.2
- orchestra/testbench: ^6.0 || ^7.0 || ^8.0 || ^9.0
- phpunit/phpunit: ^9.3.3 || ^10.0
README
User block/unblock behaviour for Laravel.
Introduction
It let people express how they feel about the model(documentation/subject/topic), prevent this model from interacting with you and sending you notifications.
Installation
Requirements
Instructions
Require Laravel Block using Composer.
composer require laravel-interaction/block
Publish configuration and migrations
php artisan vendor:publish --tag=block-config php artisan vendor:publish --tag=block-migrations
Run database migrations.
php artisan migrate
Usage
Setup Blocker
use Illuminate\Database\Eloquent\Model; use LaravelInteraction\Block\Concerns\Blocker; class User extends Model { use Blocker; }
Setup Blockable
use Illuminate\Database\Eloquent\Model; use LaravelInteraction\Block\Concerns\Blockable; class Channel extends Model { use Blockable; }
Blocker
use LaravelInteraction\Block\Tests\Models\Channel; /** @var \LaravelInteraction\Block\Tests\Models\User $user */ /** @var \LaravelInteraction\Block\Tests\Models\Channel $channel */ // Block to Blockable $user->block($channel); $user->unblock($channel); $user->toggleBlock($channel); // Compare Blockable $user->hasBlocked($channel); $user->hasNotBlocked($channel); // Get blocked info $user->blockerBlocks()->count(); // with type $user->blockerBlocks()->withType(Channel::class)->count(); // get blocked channels Channel::query()->whereBlockedBy($user)->get(); // get blocked channels doesnt blocked Channel::query()->whereNotBlockedBy($user)->get();
Blockable
use LaravelInteraction\Block\Tests\Models\User; use LaravelInteraction\Block\Tests\Models\Channel; /** @var \LaravelInteraction\Block\Tests\Models\User $user */ /** @var \LaravelInteraction\Block\Tests\Models\Channel $channel */ // Compare Blocker $channel->isBlockedBy($user); $channel->isNotBlockedBy($user); // Get blockers info $channel->blockers->each(function (User $user){ echo $user->getKey(); }); $channels = Channel::query()->withCount('blockers')->get(); $channels->each(function (Channel $channel){ echo $channel->blockers()->count(); // 1100 echo $channel->blockers_count; // "1100" echo $channel->blockersCount(); // 1100 echo $channel->blockersCountForHumans(); // "1.1K" });
Events
License
Laravel Block is an open-sourced software licensed under the MIT license.