Surya Neupane
Surya Neupane

Reputation: 994

How to redirect to two step backwards in Laravel?

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

Upvotes: 3

Views: 4148

Answers (1)

AddWeb Solution Pvt Ltd
AddWeb Solution Pvt Ltd

Reputation: 21681

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]); 

Upvotes: 1

Related Questions