Filament resource table actions offer powerful customization for crafting seamless admin experiences. Let’s explore some high-impact tricks every Laravel developer should know:
Trick 1: Automatically Mutate Form Data in the Edit Action
Need to auto-update a field every time you edit from the table? You can do this with the mutateFormDataUsing()
method in your EditAction
:
use Filament\Tables;
use Filament\Tables\Table;
public static function table(Table $table): Table
{
return $table
->columns([
// Your columns...
])
->actions([
Tables\Actions\EditAction::make()
->mutateFormDataUsing(function (array $data): array {
$data['status'] = 'updated'; // auto-set status before save
return $data;
}),
]);
}
This ensures the status
field is automatically set to "updated"
whenever an edit occurs.
Trick 2: Customize an Action to Load a View in a Modal
Standard actions don’t always cut it. For instance, you might want to display a list of users who liked a blog post in a modal. Here’s a clean way to do it:
Action::make('showLikes')
->label('Likes')
->icon('heroicon-o-heart')
->visible(fn($record) => $record->likes()->count() > 0)
->modalHeading('Likes')
->modalContent(function ($record) {
return view('filament.components.likes-list', [
'blogId' => $record->id,
]);
})
->modalSubmitAction(false)
->modalCancelAction(false)
->modalWidth('lg'),
This opens a modal showing your custom view, without extra buttons.
Trick 3: Add a State-Toggling Action with Confirmation and Notification
Want a sleek toggle for boolean flags like activation status, complete with confirmation and feedback? Try this:
Tables\Actions\Action::make('toggleActive')
->label(fn($record) => $record->is_active ? 'Deactivate' : 'Activate')
->icon(fn($record) => $record->is_active ? 'heroicon-o-x-circle' : 'heroicon-o-check-circle')
->color(fn($record) => $record->is_active ? 'danger' : 'success')
->requiresConfirmation()
->action(function ($record) {
$actionString = $record->is_active ? 'deactivated' : 'activated';
$record->update([
'is_active' => !$record->is_active,
]);
Notification::make()
->title('Blog has been ' . $actionString . ' successfully')
->success()
->send();
}),
This delivers an intuitive toggle experience—confirm first, then notify on change.
Why These Tips Matter
These action enhancements help you:
- Automate workflows (e.g., setting status instantly in edit forms).
- Visualize complex data elegantly (e.g., view likes in a modal).
- Ensure user clarity and feedback with confirmation dialogs and notifications.
This is especially valuable when building advanced admin panels with Filament—turning UI logic into polished user experiences.