Filament Ban
Ban and unban any Eloquent model directly from Filament tables with ready-to-use actions, bulk actions, an icon column and a status filter, powered by cybercog/laravel-ban.
#Filament Ban
Ban and unban any Eloquent model directly from your Filament panel. This package wraps cybercog/laravel-ban and ships ready-to-use actions, bulk actions, an icon column and a status filter for your Filament resources and tables. Inspired by cybercog/laravel-nova-ban.
#Version Compatibility
| Filament | Laravel | PHP | Branch | Version |
|---|---|---|---|---|
| v3 | 10 / 11 | 8.1+ | 1.x |
^1.0 |
| v4 | 11 / 12 | 8.2+ | 2.x |
^2.0 |
| v5 | 11.28 / 12 / 13 | 8.2+ | 3.x |
^3.0 |
All tags use plain SemVer without the v prefix (e.g. 3.0.0).
#Installation
You can install the package via composer:
composer require jeffersongoncalves/filament-ban
Publish and run the cybercog/laravel-ban migration (creates the bans table):
php artisan vendor:publish --provider="Cog\Laravel\Ban\Providers\BanServiceProvider" --tag="migrations" php artisan migrate
Then add a nullable banned_at timestamp column to each bannable model's table:
Schema::table('users', function (Blueprint $table) { $table->timestamp('banned_at')->nullable(); });
#Preparing your model
Make any Eloquent model bannable by implementing the contract and using the trait:
use Cog\Contracts\Ban\Bannable as BannableContract; use Cog\Laravel\Ban\Traits\Bannable; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable implements BannableContract { use Bannable; }
#Usage
#Actions
Add ban / unban buttons to a resource table row. Each action shows only when relevant
(Ban when the record is not banned, Unban when it is). BanAction opens a modal where
you can set an optional comment and an optional expiration date.
use JeffersonGoncalves\Filament\Ban\Actions\BanAction; use JeffersonGoncalves\Filament\Ban\Actions\UnbanAction; public function table(Table $table): Table { return $table ->recordActions([ BanAction::make(), UnbanAction::make(), ]); }
#Bulk actions
use JeffersonGoncalves\Filament\Ban\Actions\BanBulkAction; use JeffersonGoncalves\Filament\Ban\Actions\UnbanBulkAction; $table->toolbarActions([ BanBulkAction::make(), UnbanBulkAction::make(), ]);
#Column
Display the current ban status as a boolean icon:
use JeffersonGoncalves\Filament\Ban\Tables\Columns\BanColumn; $table->columns([ BanColumn::make(), ]);
#Filter
Filter records by ban status (uses the onlyBanned / withoutBanned scopes):
use JeffersonGoncalves\Filament\Ban\Tables\Filters\BanFilter; $table->filters([ BanFilter::make(), ]);
#Development
# Run static analysis composer analyse # Run tests composer test # Format code composer format
#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.