Introduction
Actions are one of Filament’s most powerful features, providing modal-based interactions throughout the framework. Custom actions extend the baseAction class and can be used in tables, forms, pages, and infolists.
Understanding the Action base class
All actions extend theAction class at packages/actions/src/Action.php. This base class provides:
- Modal management
- Form integration
- Authorization and visibility
- Notifications
- URL redirection
- Event dispatching
- Lifecycle hooks
- Multiple view modes (button, link, icon button, grouped)
Creating a basic custom action
use Filament\Actions\Action;
use Illuminate\Database\Eloquent\Model;
class PublishAction extends Action
{
public static function getDefaultName(): ?string
{
return 'publish';
}
protected function setUp(): void
{
parent::setUp();
$this->label('Publish');
$this->icon('heroicon-o-arrow-up-tray');
$this->color('success');
$this->requiresConfirmation();
$this->modalHeading('Publish this item?');
$this->modalDescription('This will make the item visible to the public.');
$this->action(function (Model $record): void {
$record->update(['published_at' => now()]);
$this->success();
});
$this->successNotificationTitle('Published successfully');
}
}
Advanced action configuration
Actions support extensive configuration through the fluent API:Creating bulk actions
Bulk actions operate on multiple selected records:Using lifecycle hooks
Actions provide comprehensive lifecycle hooks:Implementing authorization
Control who can see and use your action:Working with action data
Actions can access and manipulate data from multiple sources:Creating action groups
Group related actions together:Advanced example: Multi-step wizard action
Using database transactions
Ensure data consistency with transactions:Custom action arguments
Pass custom data to actions:Stopping action execution
You can halt or cancel action execution:Best practices
- Use
setUp()for default configuration instead of the constructor - Implement
getDefaultName()for automatic action naming - Use lifecycle hooks for complex workflows
- Always use database transactions for multi-step operations
- Provide clear modal headings and descriptions
- Use authorization methods (
visible(),authorize(),disabled()) - Follow naming conventions: use descriptive names, not abbreviations
- Use static closures when the closure doesn’t use
$this - Provide success/failure notifications
- Deselect records after bulk actions complete
- Use
evaluate()for all properties that support closures