如何在 Laravel 中返回两次?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36098589/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to return back twice in Laravel?
提问by Arthur Tarasov
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
在 Laravel 中,有一个函数return back();
,可以将用户返回到上一页。是否可以return back();
在一个函数中多次返回用户两次或多次?我试过
public function ....()
{
return back();
return back();
}
but it doesn't seem to work.
但它似乎不起作用。
回答by Alexey Mezenin
No, but you could use sessionsystem to save URLs of 2-3-4 pages back. Use Session::
facade or session()
helper for shorter syntax:
不,但您可以使用会话系统将 2-3-4 页的 URL 保存回来。使用Session::
Facade 或session()
helper 来缩短语法:
$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
回答by Labb Avdiu
it works for me Redirect::to($request->request->get('http_referrer'))
这个对我有用 Redirect::to($request->request->get('http_referrer'))