F
Filamentβ€’17mo ago
Husky110

Empty model on mountUsing

Hi - I am building an EditAction on a Resource and want to use mountUsing(). I followed the docs at https://filamentphp.com/docs/2.x/tables/actions#filling-default-data and made my function look like this:
Tables\Actions\EditAction::make()
->mountUsing(function (Forms\ComponentContainer $form, DeliveryChannel $deliveryChannel){
$filling = [
'channelname' => $deliveryChannel->channelname,
'customer_id' => $deliveryChannel->customer_id,
];
foreach ($deliveryChannel->customerdeliverychannelconfigs as $deliveryChannelConfig){
$filling[$deliveryChannelConfig->customer_id.'-'.$deliveryChannelConfig->key] = $deliveryChannelConfig->pivot->value;
}
return $form->fill($filling);
}),
Tables\Actions\EditAction::make()
->mountUsing(function (Forms\ComponentContainer $form, DeliveryChannel $deliveryChannel){
$filling = [
'channelname' => $deliveryChannel->channelname,
'customer_id' => $deliveryChannel->customer_id,
];
foreach ($deliveryChannel->customerdeliverychannelconfigs as $deliveryChannelConfig){
$filling[$deliveryChannelConfig->customer_id.'-'.$deliveryChannelConfig->key] = $deliveryChannelConfig->pivot->value;
}
return $form->fill($filling);
}),
But the modal it not beeing filled up. The form-elements themselfs are there, but have no values. DeliveryChannel is the Model bound to the Resource. A dd($deliveryChannel) revealed that the function receives an empty model. Does anyone have an idea on how to get the actual model I've clicked on the table?
Filament
Actions - Table Builder - Filament
The elegant TALL stack table builder for Laravel artisans.
Solution:
The parameter injection is based on the variable names
Jump to solution
4 Replies
Patrick Boivin
Patrick Boivinβ€’17mo ago
Try ->mountUsing(function (Forms\ComponentContainer $form, DeliveryChannel $record){ instead
Solution
Patrick Boivin
Patrick Boivinβ€’17mo ago
The parameter injection is based on the variable names
Husky110
Husky110OPβ€’17mo ago
Thanks - you're the man! πŸ™‚
Want results from more Discord servers?
Add your server