Alex Jolley
Alex Jolley

Reputation: 21

Redirect back two (2) pages in Laravel

I have an form on an edit screen and on submit I want to redirect back two pages.

Is there a way to do this in Laravel? I haven't been able to find anything online.

Thanks!

Upvotes: 2

Views: 3535

Answers (1)

Thomas
Thomas

Reputation: 8849

Laravel redirects back using either the Referer HTTP header or an internal session key _previous.url which changes on every request. So there is nothing in Laravel that specifically redirects back two pages.

As @kerbholz mentioned you could simply redirect to the correct page.

If you can't do that you could manually store the URL to redirect to in the session on the page you want to redirect to:

session(['previous-url' => request()->url());

And redirect after the form is submitted:

return redirect(session('previous-url'));

Upvotes: 6

Related Questions