PHP code example of laravel-interaction / block

1. Go to this page and download the library: Download laravel-interaction/block library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

laravel-interaction / block example snippets


use Illuminate\Database\Eloquent\Model;
use LaravelInteraction\Block\Concerns\Blocker;

class User extends Model
{
    use Blocker;
}

use Illuminate\Database\Eloquent\Model;
use LaravelInteraction\Block\Concerns\Blockable;

class Channel extends Model
{
    use Blockable;
}

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();

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"
});
bash
php artisan vendor:publish --tag=block-config
php artisan vendor:publish --tag=block-migrations
bash
php artisan migrate