Skip to content

ElegantEngineeringTech/laravel-banhammer

Repository files navigation

This is my package laravel-banhammer

Latest Version on Packagist Tests Code Style PHPStan Level Laravel Pint Total Downloads

A simple package to ban an model (users, teams...).

Installation

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

Usage

Prepare your models:

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

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Sponsor this project

Languages