Notification Action - V4

I have a notification in my custom action class as a guide from this document. I encounter an error Unable to call component method. Public method [mountAction] not found on component not sure if this is known issue in v4 beta-10. here is my code snippet:
class DeleteRecordAction
{

public static function make()
{
return Action::make('delete_record')
->label('Delete')
->hidden(static function (User $record): bool {
if (! method_exists($record, 'trashed')) {
return false;
}

return $record->trashed();
})
->defaultColor('danger')
->tableIcon(Heroicon::Trash)
->groupedIcon(Heroicon::Trash)
->modalIcon(Heroicon::OutlinedTrash)
->modalHeading(fn (): string => __('filament-actions::delete.single.modal.heading', ['label' => 'Record']))
->requiresConfirmation()
->action(function (User $record){
$result = (bool) $record->delete();
if (! $result) {
Notification::make()
->title('Something went wrong')
->body('Unable to delete record.')
->color('danger')
->send();
}
Notification::make()
->title('Deleted successfully')
->body('Record successfully deleted.')
->color('success')
->duration(6500) // 6.5 sec
->actions([
Action::make('Undo')
->button()
->action(fn(User $model) => $model->restore()) // => This cause an error
])
->send();
});
}
class DeleteRecordAction
{

public static function make()
{
return Action::make('delete_record')
->label('Delete')
->hidden(static function (User $record): bool {
if (! method_exists($record, 'trashed')) {
return false;
}

return $record->trashed();
})
->defaultColor('danger')
->tableIcon(Heroicon::Trash)
->groupedIcon(Heroicon::Trash)
->modalIcon(Heroicon::OutlinedTrash)
->modalHeading(fn (): string => __('filament-actions::delete.single.modal.heading', ['label' => 'Record']))
->requiresConfirmation()
->action(function (User $record){
$result = (bool) $record->delete();
if (! $result) {
Notification::make()
->title('Something went wrong')
->body('Unable to delete record.')
->color('danger')
->send();
}
Notification::make()
->title('Deleted successfully')
->body('Record successfully deleted.')
->color('success')
->duration(6500) // 6.5 sec
->actions([
Action::make('Undo')
->button()
->action(fn(User $model) => $model->restore()) // => This cause an error
])
->send();
});
}
Solution:
only URLs and dispatches, not function calls
Jump to solution
11 Replies
Dan Harrin
Dan Harrin4mo ago
How are you using the DeleteRecordAction on your page?
ShapeShifter
ShapeShifterOP4mo ago
I'm using it in my table as a recordActions and plan to use it on the View Page.
Dan Harrin
Dan Harrin4mo ago
is your table in a resource or on a custom page
ShapeShifter
ShapeShifterOP4mo ago
in a resource
Dan Harrin
Dan Harrin4mo ago
please open a bug report with a reproduction repository
ShapeShifter
ShapeShifterOP4mo ago
bug reported. Thanks.
GitHub
filamentphp/filament
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
Dan Harrin
Dan Harrin4mo ago
ah i see, we dont support notification actions
Solution
Dan Harrin
Dan Harrin4mo ago
only URLs and dispatches, not function calls
Dan Harrin
Dan Harrin4mo ago
sorry i wasnt reading the code snippet properly originally. its nothing to do with it being a custom action class though, this never worked in v3 either
ShapeShifter
ShapeShifterOP4mo ago
I see, will it be a feature in the future?
Dan Harrin
Dan Harrin4mo ago
i dont know a way in which it would be possible, no for a notification to be sent, its entire configuration needs to be serialised to JSON but you cant safely serialise a function like that really

Did you find this page helpful?