PHP code example of hkp22 / laravel-bannable

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

    

hkp22 / laravel-bannable example snippets


'providers' => [
    Qirolab\Laravel\Bannable\BannableServiceProvider::class,
],



use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddBannedAtColumnToUsersTable extends Migration
{
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->timestamp('banned_at')->nullable();
        });
    }

    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn('banned_at');
        });
    }
}

$user->ban();

$user->ban([
    'comment' => 'ban comment!',
]);

$user->ban([
    'expired_at' => '2086-03-28 00:00:00',
]);

$user->ban([
    'expired_at' => '+1 year',
]);

$date = Carbon::now()->addWeeks(2);

$user->ban([
    'expired_at' => $date,
]);

$user->unban();

$user->isBanned();

$user->isNotBanned();

Qirolab\Laravel\Bannable\Models\Ban::deleteExpired();

$users = User::withoutBanned()->get();

$users = User::withBanned()->get();

$users = User::onlyBanned()->get();

/**
 * Determine which BannedAtScope should be applied or not.
 *
 * @return bool
 */
public function disableBannedAtScope()
{
    return true;
}
bash
php artisan migrate