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 one function to return the user back twice or several times? I tried
public function ....()
{
return back();
return back();
}
but it doesn't seem to work.
No, but you could use session system to save URLs of 2-3-4 pages back. Use Session::
facade or session()
helper for 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 to use it:
return redirect(session('links')[2]); // Will redirect 2 links back
it works for me Redirect::to($request->request->get('http_referrer'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With