Bulk action with relationship toggles

I have to update a belongsToMany relationship via BulkActions. Let's say I have a modal where I put the values of the realted model and let the user select what are going to be attached so then I can update the pivot table based on the values given. I don't find a proper field or way to do this. my toggles generation looks like this:
IntegrationAccount::get()
->map(function ($integrationAccount) {
return [
Forms\Components\Toggle::make("integration_account[{$integrationAccount->id}][is_enabled]")
->label($integrationAccount->label)
->default(false),
];
})
->flatten(1)
->toArray()
IntegrationAccount::get()
->map(function ($integrationAccount) {
return [
Forms\Components\Toggle::make("integration_account[{$integrationAccount->id}][is_enabled]")
->label($integrationAccount->label)
->default(false),
];
})
->flatten(1)
->toArray()
No description
1 Reply
lukevi
lukevi8mo ago
I think the way is on your BulkAction, add the action() method like so:
->action(function (Collection $selectedRecords, $livewire) {
$data = $livewire->getMountedTableBulkActionForm()->getState();
// .. your update code
})
->action(function (Collection $selectedRecords, $livewire) {
$data = $livewire->getMountedTableBulkActionForm()->getState();
// .. your update code
})
Want results from more Discord servers?
Add your server