A simple package to ban an model (users, teams...).
You can install the package via composer:
composer require elegantly/laravel-banhammer
First, publish the config with:
php artisan vendor:publish --tag="banhammer-config"
Then define the bannable models in the config file like this:
use Elegantly\Banhammer\Models\Ban;
use Illuminate\Foundation\Auth\User;
return [
'model_ban' => Ban::class,
'model_user' => User::class,
'bannables' => [
\App\Models\User::class,
// \App\Models\Team::class
],
];
Next, publish and run the migrations with:
php artisan vendor:publish --tag="banhammer-migrations"
php artisan migrate
Finally schedule the command from bootstrap/app.php
with:
use Illuminate\Foundation\Application;
use Illuminate\Console\Scheduling\Schedule;
use Elegantly\Banhammer\Commands\DenormalizeBannableCommand;
return Application::configure(basePath: dirname(__DIR__))
// ...
->withSchedule(function (Schedule $schedule) {
$schedule->command(DenormalizeBannableCommand::class)->everyMinute();
})
->create();
Or from routes/console.php
with:
use Illuminate\Support\Facades\Schedule;
use Elegantly\Banhammer\Commands\DenormalizeBannableCommand;
Schedule::command(DenormalizeBannableCommand::class)->everyMinute();
namespace App\Models;
use Elegantly\Banhammer\Models\Concerns\Bannable;
use Elegantly\Banhammer\Models\Contracts\BannableContract;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable implements BannableContract
{
use Bannable;
}
$user->ban(
level: 0,
reason: "spam",
from: now(),
until: null,
);
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.