Custom Action successRedirectUrl
Hello everyone, Is there a way to trigger succesRedirectUrl and successNotification after an action is successful?
7 Replies
I think you can use Lifecycle hook
https://filamentphp.com/docs/3.x/panels/resources/creating-records#lifecycle-hooks and do the thing you want to do
here is the redirect code from the documentation
protected function getRedirectUrl(): string
{
return $this->getResource()::getUrl('index');
}
here is the saved when successfull
use Filament\Notifications\Notification;
protected function getSavedNotification(): ?Notification
{
return Notification::make()
->success()
->title('User updated')
->body('The user has been saved successfully.');
}
I have this code on a Custom Page:
It gets the job done to some extent, but I'm wondering if there's a better alternative...also there's no redirect, only a manual Notification.
Please read our #✅┊rules and format your code properly. It's very hard to read otherwise
Hello, thanks, I edited my previous message, to follow the rules.
try:
protected function getFormActions(): array
{
return [
Action::make('save')
->label(__('filament-panels::resources/pages/edit-record.form.actions.save.label'))
->submit('save')
->after(function ($record) {
redirect(SomeResource::getUrl('view', ['record' => $record]));
}),
];
}