#getRedirectUrl() can be set globally?

6 messages · Page 1 of 1 (latest)

dense nimbus
#

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');
    }

Is there a way to put that globally?

Thanks.

fringe flaxBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

tawdry sonnet
#

Create a class that extends the base class and extend all your pages from that class.

dense nimbus
#

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.

tawdry sonnet
#

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.

dense nimbus
#

Perfect. Thank you. I will give that a try.