3

For example In controller I have a store function

public function store(Request $request)
{
 ....
 return redirect()->back();
 }

After store function is called, it goes to the create.blade.php view because of return redirect()->back(). But I want to redirect to further one step backwards. How can I do that ? Thank You

Surya Neupane
  • 906
  • 10
  • 20

1 Answers1

1

You can use the Session system to save the URL all pages back. Check below steps to redirect 2 or 3 backward URL redirect.

1) First, you can get the all URLs from session system variable.

$urls = array();
  if(Session::has('links')){
     $urls[] = Session::get('links')
  }

2) Then get the current page url.

  $currentUrl = $_SERVER['REQUEST_URI'];

3) Mapping with current url to other all url.

array_unshift($urls, $currentUrl);
  Session::flash('urls', $urls);

4) Get all Links fetch from session system like below

  $links = Session::get('urls'); 

5) Then You can redirect to a particular page.

   return redirect($links[2]); 
AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57
  • Dude, you've just copied the code [from my answer](https://stackoverflow.com/questions/36098589/how-to-return-back-twice-in-laravel) (see [version of the answer before the last edit](https://stackoverflow.com/revisions/36098635/6)). I don't mind if you would add something cool to the idea. I mean like a better solution. But why just copy it? BTW, I've just refactored code to make it modern and more elegant. – Alexey Mezenin Dec 19 '17 at 07:49
  • $urls = array(); if(Session::has('links')){ $urls[] = Session::get('links'); } ; is missing – Gauravbhai Daxini May 09 '18 at 11:29