PHP code example of gerenuk / filament-banhammer

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

    

gerenuk / filament-banhammer example snippets


return [
    // The resource the plugin registers.
    'resource' => \Gerenuk\FilamentBanhammer\Resources\BanhammerResource::class,

    'navigation_group' => 'Admin',

    // Whether an export action is included on the resource.
    'show_export' => true,

    // The exporter used by the export bulk action.
    'exporter' => \Gerenuk\FilamentBanhammer\Exports\BanExporter::class,

    // See "Trashed Bans" below.
    'trashed' => [
        'enabled' => true,
        'force_delete' => false,
    ],

    // See "IP Blocking" below.
    'ip_blocking' => [
        'enabled' => true,
    ],

    // See "Country Blocking" below.
    'country_blocking' => [
        'enabled' => false,
        'resource' => \Gerenuk\FilamentBanhammer\Resources\BlockedCountryResource::class,
    ],

    // See "Authorization" below.
    'authorization' => [
        'ban' => 'ban',
        'edit_ban' => 'editBan',
        'unban' => 'unban',
        'ban_ip' => 'banIp',
    ],

    // Per-action label, colour, icon, confirmation and notification titles.
    // `ban`, `edit_ban`, `unban`, `ban_bulk`, `edit_ban_bulk`, `unban_bulk`
    // and `ban_ip` all share this shape — here's `ban`:
    'actions' => [
        'ban' => [
            'label' => 'ban',
            'colour' => 'warning',
            'icon' => 'heroicon-o-no-symbol',
            '



namespace App\Providers\Filament;

use Filament\Panel;
use Filament\PanelProvider;
use Gerenuk\FilamentBanhammer\FilamentBanhammerPlugin;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugin(FilamentBanhammerPlugin::make());
    }
}

public function getFilamentBanhammerTitleAttribute()
{
    return $this->name;
}

use Filament\Tables\Table;
use Gerenuk\FilamentBanhammer\Resources\Actions\BanAction;

public static function table(Table $table): Table
    {
        return $table
            ->columns([
                // ...
            ])
            ->recordActions([
                BanAction::make(),
            ]);
    }

use Filament\Tables\Table;
use Gerenuk\FilamentBanhammer\Resources\Actions\UnbanAction;

public static function table(Table $table): Table
    {
        return $table
            ->columns([
                // ...
            ])
            ->recordActions([
                UnbanAction::make(),
            ]);
    }

use Filament\Tables\Table;
use Gerenuk\FilamentBanhammer\Resources\Actions\BanBulkAction;

public static function table(Table $table): Table
    {
        return $table
            ->columns([
                // ...
            ])
            ->toolbarActions([
                BanBulkAction::make(),
            ]);
    }

use Filament\Tables\Table;
use Gerenuk\FilamentBanhammer\Resources\Actions\UnbanBulkAction;

public static function table(Table $table): Table
    {
        return $table
            ->columns([
                // ...
            ])
            ->toolbarActions([
                UnbanBulkAction::make(),
            ]);
    }

class UserPolicy
{
    public function ban(?User $user, User $target): bool
    {
        return $user?->isAdmin() ?? false;
    }
}

'trashed' => [
    'enabled' => true,
    'force_delete' => false,
],

'ip_blocking' => [
    'enabled' => false,
],

'country_blocking' => [
    'enabled' => true,
],
bash
php artisan vendor:publish --tag="filament-banhammer-migrations"
bash
php artisan vendor:publish --tag="filament-banhammer-config"