PHP code example of cjmellor / blockade

1. Go to this page and download the library: Download cjmellor/blockade 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/ */

    

cjmellor / blockade example snippets


return [
    /**
     * If your User model different to the default, you can specify it here.
     */
    'user_model' => 'App\Models\User',
    
    /**
     * Specify the user model's foreign key.
     */
    'user_foreign_key' => 'user_id',

    /**
     * Specify the table name for the blocks table.
     */
    'blocks_table' => 'blocks',

    /**
     * Specify the foreign key for the blocker.
     */
    'blocker_foreign_key' => 'blocker_id',

    /**
     * Specify the foreign key for the blocked.
     */
    'blocked_foreign_key' => 'blocked_id',

    /**
     * Schedule the cleanup of expired blocks.
     */
    'schedule_cleanup' => false,
];


use Cjmellor\Blockade\Concerns\CanBlock;

class User
{
    use CanBlock;
    
    // ...
}

use Cjmellor\Blockade\Concerns\HasBlocked;

class Comment
{
    use HasBlocked;
    
    // ...
}

$user->block(User::find(2)));

// or

$user->block(2);

$user->unblock(User::find(2)));

// or

$user->unblock(2);

$user->isBlocking(User::find(2)));

// or

$user->isBlocking(2);

$user->block(User::find(2), expiresAt: now()->addDays(7)));

$schedule->command('unblock:expired')->everyMinute();
bash
php artisan vendor:publish --tag="blockade-migrations"

php artisan migrate
bash
php artisan vendor:publish --tag="blockade-config"
bash
php artisan unblock:expired