Custom Action successRedirectUrl

Hello everyone, Is there a way to trigger succesRedirectUrl and successNotification after an action is successful?
7 Replies
Topherllobrera
Topherllobrera2mo ago
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.'); }
nuovo2023
nuovo2023OP2mo ago
I have this code on a Custom Page:
protected function getFormActions(): array
{
return [
Action::make('save')
->label(__('filament-panels::resources/pages/edit-record.form.actions.save.label'))
->submit('save'),
];
}

public function save(): void
{
try {
// @phpstan-ignore-next-line
$data = $this->form->getState();
$this->provider->update($data);
} catch (Halt $exception) {
return;
}

Notification::make()
->success()
->title(__('filament-panels::resources/pages/edit-record.notifications.saved.title'))
->send();
}
protected function getFormActions(): array
{
return [
Action::make('save')
->label(__('filament-panels::resources/pages/edit-record.form.actions.save.label'))
->submit('save'),
];
}

public function save(): void
{
try {
// @phpstan-ignore-next-line
$data = $this->form->getState();
$this->provider->update($data);
} catch (Halt $exception) {
return;
}

Notification::make()
->success()
->title(__('filament-panels::resources/pages/edit-record.notifications.saved.title'))
->send();
}
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.
Dennis Koch
Dennis Koch2mo ago
Please read our #✅┊rules and format your code properly. It's very hard to read otherwise
nuovo2023
nuovo2023OP2mo ago
Hello, thanks, I edited my previous message, to follow the rules.
Sydd
Sydd2mo ago
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])); }), ]; }
Want results from more Discord servers?
Add your server