How to send a success notification after a custom action ?
Hello, i'm trying to send a notification after a custom action but no notification get fired.
My code :
Action::make('reset_user_password')
->action(
fn (User $record) => $this->resetPassword($record)
)
->requiresConfirmation()
->successNotification(
Notification::make()
->success()
->title('User password reset!'),
);
11 Replies
You have to ->send() the Notification.
Add that as the last method to your Notification.
Even inside a successNotification()?
I use the same syntax with the prebuild actions and the successNotification works as intended! It's. only with this custom one that i get noting.
Yes. The prebuilt actions are calling it on their own. If you new up the class then you have to send it.
Hum.. with the send(), the notification is fired every time the page is updated
please share your code with the send()
Ok. Since you are using a custom action.
But since you are in a custom action you can also just send the notification directly in the ->action() since there's no need to register it like you would on a prebuilt action:
Either way. '->successNotification()` only registers the notification that will be called when the action is run. So you still have to 'call' it in your '->action()'
With this one the sendSuccessNotification is not found.
Solution
But sending the notification directly in the action works!
Makes sense. Depends on what class the underlying action. You should check out the prebuilt actions code sometime. It’ll give a better understanding of how they work. Once you have that you can even make your own reusable pre built actions. If you need them. Glad you have it working though. Cheers.
Thx for the help I will look into it