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:
Is there a way to put that globally?
Thanks.
4 Replies
Create a class that extends the base class and extend all your pages from that class.
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.
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.Perfect. Thank you. I will give that a try.