Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

earmsby's avatar

prompt for input in bulk action?

I have a bulk action on a Filament relation manager that allows the user to move a group of works from one contract to another. Right now (for development) I have hard coded the new contract to move the works to like so:

BulkAction::make('move')
                        ->icon(Heroicon::ArrowRight)
                        ->label('Move to contract')
                        ->action(function (Collection $records) {
                            $thisContract=Contract::find($this->ownerRecord->id);
                            $newContract=Contract::find(18);
                            $worksMovedCount=0;
                            foreach ($records as $record) {
                                $newContract->works()->attach($record->id);
                                $thisContract->works()->detach($record->id);
                                $worksMovedCount++;
                            }
                            if($worksMovedCount > 0){
                                Notification::make()
                                    ->success()
                                    ->title('Works moved')
                                    ->body($worksMovedCount . ' works were moved to new contract')
                                    ->send();
                            }
                        })

As you can see, I've simply hard coded the id for the new contract in this line $newContract=Contract::find(18); What I'm trying to do is have a modal where the user would select which contract to move the works to and then that value would be used instead of my hard coded value. But I'm not sure where to start with that. Is this even possible?

0 likes
2 replies
LaryAI's avatar
Level 58

Yes, this is possible! In Filament, bulk actions can include a modal form where you prompt for additional input before running the action. In your case, you want to let the user select a new contract.

You do this via the ->form() method on your bulk action. Here’s how you can update your bulk action to prompt the user to select a contract before moving the works:

Key Points:

  • The ->form([...]) method adds input fields to the modal, shown to the user when they initiate the bulk action.
  • The value the user selects is available in the $data array passed to the action.
  • Replace \App\Models\Contract::pluck('name', 'id') with whatever field you use to identify the contract in your database.

With this approach, the user can choose which contract to move works to each time they use the bulk action!

earmsby's avatar

Not quite for Filament 4... If anyone else is needing this for filament 4+, the syntax has changed. This worked:

->schema([
                            Select::make('new_contract_id')
                                ->options(Contract::all()->pluck('contract_selector', 'id'))
                                ->required(),
                        ])

Please or to participate in this conversation.