F
Filament2mo ago
Azorky

Mount action from resource

self::getGLAccountField()
->live()
->afterStateUpdated(fn ($livewire) => $livewire->mountAction('changeLineItemGlAccount')),
self::getGLAccountField()
->live()
->afterStateUpdated(fn ($livewire) => $livewire->mountAction('changeLineItemGlAccount')),
I want to mount an action in my resource using the above code. When using this code on a custom Livewire page, this works, but in my resource I cannot get it to work. I cannot seem to find anything in the docs mentioning how to mount actions like this in a resource.
Solution:
I solved the issue. This code needed to be present on the Create and Edit pages, not on the resource itself
Jump to solution
2 Replies
Azorky
AzorkyOP2mo ago
use Filament\Actions\Action as ActionsAction;

public function changeLineItemGlAccountAction(): ActionsAction
{
return ActionsAction::make('changeLineItemGlAccount')
->requiresConfirmation()
->modalHeading(__('resources/gl-accounts.change_all_lines'))
->modalDescription(__('resources/gl-accounts.change_all_lines_description'))
->modalCancelActionLabel(__('general.no'))
->modalSubmitActionLabel(__('general.yes'))
->action(function () {
$glAccountId = $this->data['gl_account_id'];

foreach ($this->data['lineItems'] as &$lineItem) {
$lineItem['gl_account_id'] = $glAccountId;
}
});
}
use Filament\Actions\Action as ActionsAction;

public function changeLineItemGlAccountAction(): ActionsAction
{
return ActionsAction::make('changeLineItemGlAccount')
->requiresConfirmation()
->modalHeading(__('resources/gl-accounts.change_all_lines'))
->modalDescription(__('resources/gl-accounts.change_all_lines_description'))
->modalCancelActionLabel(__('general.no'))
->modalSubmitActionLabel(__('general.yes'))
->action(function () {
$glAccountId = $this->data['gl_account_id'];

foreach ($this->data['lineItems'] as &$lineItem) {
$lineItem['gl_account_id'] = $glAccountId;
}
});
}
This function is present in the resource
Solution
Azorky
Azorky2mo ago
I solved the issue. This code needed to be present on the Create and Edit pages, not on the resource itself

Did you find this page helpful?