F
Filament6mo ago
Carlo

Filament Action inside a custom Livewire component

I'm basically using Actions and Forms outside the Filament Panel and I'm stuck on the edit action which is I'm trying to do (this is inside a loop). I wanted to have an edit action for each item and load the modal form which is I'm also using for create action (create is working) I'm just stuck on the edit action part. I'm not sure if I'm doing this right and I can't find any reference in the docs.
No description
No description
Solution:
Yes, all components were loaded. I managed to make it work by creating a child component listingItem to handle each item. Thanks for responding @gladjanus43...
No description
No description
Jump to solution
2 Replies
gladjanus43
gladjanus436mo ago
Did you load the actions component? Let me look up, i have used actions in loops as well One thing I now is that you must have the same name for the function and the action. This is the code that works for me:
public function orderToInvoiceAction(): Action
{
return Action::make('orderToInvoice')
->icon('heroicon-s-currency-euro')
->iconButton()
->color('white')
->requiresConfirmation()
->action(function (array $arguments, $action) {
$order = Order::findOrFail($arguments['order']);
Pricing::generateInvoice($order, false);
})
->tooltip('Genereer invoice')
->modalSubmitAction(fn (StaticAction $action) => $action->color('primary'));
}
public function orderToInvoiceAction(): Action
{
return Action::make('orderToInvoice')
->icon('heroicon-s-currency-euro')
->iconButton()
->color('white')
->requiresConfirmation()
->action(function (array $arguments, $action) {
$order = Order::findOrFail($arguments['order']);
Pricing::generateInvoice($order, false);
})
->tooltip('Genereer invoice')
->modalSubmitAction(fn (StaticAction $action) => $action->color('primary'));
}
the action::make must match the function name! Something to do with caching I think. And then in your view just pass the argument to the action like this: {{($this->orderToInvoiceAction)(['order' => $record->id])}}
Solution
Carlo
Carlo6mo ago
Yes, all components were loaded. I managed to make it work by creating a child component listingItem to handle each item. Thanks for responding @gladjanus43
No description
No description
Want results from more Discord servers?
Add your server