Laravel Filament Bulk action: how to set form and get values from there

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Laravel Filament Bulk Action: How to Set Form Values and Get Data in the action() Method

As developers building complex interfaces with Laravel and Filament, we frequently encounter scenarios where user input gathered via modals or forms needs to influence subsequent operations, such as a bulk action. The specific challenge you've outlined—accessing data entered into a nested form within a Filament Bulk Action's action() method—is common.

The short answer is that the values from the form are typically accessible by operating on the records being processed or by accessing the context provided by the framework, rather than directly extracting form field names inside the closure. Understanding the flow of data in Filament is crucial for mastering these interactions.

Understanding Filament Bulk Action Data Flow

When you define a bulk action with a nested form using the form() method, you are essentially defining an interactive state layer on top of the underlying Eloquent records. The key to accessing this newly submitted data lies in how the $action closure is executed and what context it receives, especially when dealing with collections of records.

In your example:

$table->bulkActions([
    \Filament\Tables\Actions\BulkAction::make('my_action')
        ->requiresConfirmation()
        ->form(function (Collection $records) {
            \Filament\Forms\Components\TextInput::make('name')
        })
        ->action(function (Collection $records) {
            //i need a value of form TextInput [name] here
        });
]);

The $records passed to the action() method is a Collection of models that were selected for the bulk action. The values entered into the form are typically submitted as part of the overall request payload. To retrieve these, you need to ensure the data is merged back into the records before the action executes, or access the specific record context.

The Solution: Merging Form Data with Record Updates

Since the form submission happens outside the immediate scope of the action() callback, the best practice is to handle the data collection and merging before the final action logic runs. You typically need to iterate over the selected records and apply the changes made in the form.

Here is a practical approach demonstrating how you can achieve this data synchronization:

$table->bulkActions([
    \Filament\Tables\Actions\BulkAction::make('my_action')
        ->requiresConfirmation()
        ->form(function (Collection $records) {
            // Define the form fields. The submitted data will be associated with these records.
            \Filament\Forms\Components\TextInput::make('name')
                ->label('New Name')
                ->reactive() // Important for real-time updates if needed
                ->live(debounce: 500)
                ->afterStateUpdated(function (Set $set, \Filament\Support\Bag $data, $state) {
                    // Optional: Do something on change
                });
        })
        ->action(function (Collection $records) {
            // 1. Access the submitted form data context.
            // In many Filament setups, if the form updates the underlying model state correctly,
            // you can access the updated values directly from the collection iteration.

            foreach ($records as $record) {
                // Retrieve the value set by the form component for this specific record.
                $newName = $record->name ?? $record->name; // Use null coalescing for safety
                
                // 2. Apply the changes to the Eloquent model.
                $record->update(['name' => $newName]);

                // Note: If you were adding new records, this is where you'd use Model::create()
            }

            // Return a success message for user feedback
            return onSuccessfulUpdate(); 
        });
]);

Best Practices and Laravel Context

Notice that the form component itself doesn't directly expose its submitted values to the action() closure. Instead, we leverage the fact that when Filament processes the request, it ensures the data entered in the form is reflected back onto the $records collection before the action() method is invoked. This pattern relies heavily on Laravel's robust request lifecycle and Eloquent relationships.

When dealing with complex data manipulation in Laravel applications, ensuring transactional integrity and correct model state management is paramount. Filament builds upon these fundamentals, making it essential to understand how its components interact with your underlying models. For deeper dives into Eloquent patterns that underpin this functionality, exploring resources on the Laravel Company website can provide excellent context.

Conclusion

Accessing form values within a Filament Bulk Action requires shifting perspective from directly reading form input inside the action to understanding the data synchronization pipeline. By iterating over the provided $records collection and applying the changes made in the form submission to each model, you successfully bridge the gap between user interaction (the form) and backend execution (the action). This approach ensures that your bulk operations are both dynamic and correctly persisted within your Laravel application structure.