1

I have an index page where all the models are shown and when you click edit you go to edit page and after you change something you click update and you will be redirected to index, all fine there.

And now i have made a show view and in show view i made the same edit button to go to edit page and when you click update of course you will be redirected of to the index page and i don't want that. I want to redirect user to the page where the EDIT button was clicked.

How can i redirect users to the page where they actually clicked the edit button?

lewis4u
  • 14,256
  • 18
  • 107
  • 148

2 Answers2

2

You can keep URL in session to go two pages back in Laravel:

$links = session->has('links') ? session('links') : []; // Get data from session
array_unshift($links, $_SERVER['REQUEST_URI']); // Add current URI to an array
session(compact('links')); // Save an array to session

Then you can go 2 pages back:

return redirect(session('links')[2]);
Community
  • 1
  • 1
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
0

You can use:

return back();

It returns you to back as it is so obvious. You can research this and other helper functions here:

https://laravel.com/docs/5.3/helpers#method-back

  • Read the question carefully. Alexey has the right answer. I don't want to go back one page...but two! – lewis4u Dec 13 '16 at 11:02
  • It was a bit complicated to understand the problem. Can you paste your update method in your controller? I think we can solve it with a named route. – Orkhan Farmanli Dec 13 '16 at 11:07
  • The problem is that i don't want to redirect the user always to the same page after edit....i want to redirect him to the page from where he clicked the edit button....and there is no option in laravel for that...you need to catch the URL before "back" and that is exactly what Alexey answered – lewis4u Dec 13 '16 at 11:10