How to return twice to Laravel?

In Laravel, there is a function return back(); which returns the user to the previous page. Is it possible to return back(); more than once within the same function to return the user twice or several times? I tried

 public function ....() { return back(); return back(); } 

but it does not work.

+5
source share
1 answer

No, but you can use session to save URLs 2-3-4 pages back. Use the Session:: facade or session() helper for a shorter syntax :

 $links = session()->has('links') ? session('links') : []; $currentLink = request()->path(); // Getting current URI like 'category/books/' array_unshift($links, $currentLink); // Putting it in the beginning of links array session(['links' => $links]); // Saving links array to the session 

And use it:

 return redirect(session('links')[2]); // Will redirect 2 links back 
+7
source

Source: https://habr.com/ru/post/1245367/


All Articles