getRedirectUrl() can be set globally?

In all my resources, absolutely all, I want the redirec to the index after creating and after editing records. I am using this code in every single CreateNameOfResource.php and EditNameOfResource.php:
protected function getRedirectUrl(): string
{
return $this->getResource()::getUrl('index');
}
protected function getRedirectUrl(): string
{
return $this->getResource()::getUrl('index');
}
Is there a way to put that globally? Thanks.
4 Replies
Dennis Koch
Dennis Koch16mo ago
Create a class that extends the base class and extend all your pages from that class.
Albert Lens
Albert LensOP16mo ago
Any tips on where I can begin with that? I am sorry but this will be my fist time creating this kind of classes. Thanks.
Dennis Koch
Dennis Koch16mo ago
If you don't understand the concept, look it up in the PHP docs: https://www.php.net/manual/en/language.oop5.inheritance.php Otherwise: - Create a new class whereever you want (e.g.App/Filament/Pages/CreatePage). - Make that class extend Filament's CreateRecord class - Overwrite your getRedirectUrl() - Use that class in all of your Create... pages. It's no global approach, but I don't think there is one in this case. But you don't have to repeat the code this way.
Albert Lens
Albert LensOP16mo ago
Perfect. Thank you. I will give that a try.
Want results from more Discord servers?
Add your server