Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

thewebartisan7's avatar

Custom redirect for Request validation

I need to redirect to custom route name if validation failed.

I see that I can use:

    protected $redirectRoute = 'my.route.name';

However, I need to pass params to this url.

Seem that there is no way to do this as FormRequest use only route name, I found this method:

    protected function getRedirectUrl()
    {
        $url = $this->redirector->getUrlGenerator();

        if ($this->redirect) {
            return $url->to($this->redirect);
        } elseif ($this->redirectRoute) {
            return $url->route($this->redirectRoute); // Route name is here without param
        } elseif ($this->redirectAction) {
            return $url->action($this->redirectAction);
        }

        return $url->previous();
    }
0 likes
0 replies

Please or to participate in this conversation.