PHP code example of stylers / laravel-ban

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

    

stylers / laravel-ban example snippets


use Stylers\LaravelBan\Contracts\Models\Traits\BannableInterface;
use Stylers\LaravelBan\Models\Traits\Bannable;

class User extends Authenticatable implements BannableInterface
{
    use Notifiable;
    use Bannable;
}

use Carbon\Carbon;

$user = User::first();

$comment = "Reason of ban."; // ?string
$startAt = Carbon::addWeek(); // ?DateTimeInterface
$endAt = Carbon::now()->addWeeks(2); // ?DateTimeInterface

$ban = $user->ban(); // Ban without comment and timestamps (start_at, end_at) - never expire
$ban = $user->ban($comment, null, $endAt); // Ban for 2 weeks with comment
$ban = $user->ban($comment); // Ban without expire
$ban = $user->ban($comment, $startAt, $endAt); // Ban for a week with comment from next week

$user = User::first();
$unbans = $user->unban();

use Stylers\LaravelBan\Events\Banned;
use Stylers\LaravelBan\Events\Unbanned;

use Stylers\LaravelBan\Http\Middleware\CheckUserBan;

protected $routeMiddleware = [
    ...
    'check_user_ban' => CheckUserBan::class,
];

protected function mapWebRoutes()
{
    Route::middleware('web', 'check_user_ban')
         ->namespace($this->namespace)
         ->group(base_path('routes/web.php'));
}
bash
php artisan vendor:publish --provider="Stylers\LaravelBan\Providers\BanServiceProvider"
bash
php artisan migrate