Use BulkAction's form field in action for each in bulk

Bulk action needs to get a client id to assign to each in the collection I see how to select a client. and how to each assign and save(). How to get the client->id from the Select and pass it it to the action? ```Tables\Actions\BulkAction::make('assign_to_client') ->form([ Forms\Components\Select::make('client_id') ->options(Client::pluck('name', 'id')), ]) ->action(fn (Collection $records) => $records->each( function ( $record, $get ) { //error. Value of type int is not callable $record->client_id = $get('client_id'); // Hardcoded works $record->client_id = 9; $record->save(); } ))
2 Replies
krekas
krekas7mo ago
->action(function (Collection $records, array $data): void {
// do your stuff
})
->action(function (Collection $records, array $data): void {
// do your stuff
})
ddoddsr
ddoddsrOP7mo ago
Thanks That helps!
```Tables\Actions\BulkAction::make('assign_to_client') ->form([ Forms\Components\Select::make('client_id') ->options(Client::pluck('name', 'id')), ]) ->action(function (Collection $records, array $data): void { foreach ($records as $record) { $record->client_id = $data['client_id']; $record->save(); } })
Want results from more Discord servers?
Add your server