php 将url重定向到laravel中的上一页

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38482742/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:35:44  来源:igfitidea点击:

Redirect url to previous page in laravel

phplaravel-5.2

提问by Nikhil Radadiya

How to redirect to previous page in laravel5.2 like URI Referrer in php.

如何像 php 中的 URI Referrer 一样重定向到 laravel5.2 中的上一页。

I've tried $request->url(); but it gets the current url.

我试过 $request->url(); 但它获取当前网址。

I've a form and list pages.There are many lists that redirects to form.but I want to go to that specific page after submit.

我有一个表单和列表页面。有很多列表重定向到表单。但我想在提交后转到该特定页面。

For Ex:There are a Project and Client list. If I go to form from project then it should go to project and if I go to form from client list It should go to client list page after submitting a form.

例如:有一个项目和客户列表。如果我从项目转到表格,那么它应该转到项目,如果我从客户列表转到表格,它应该在提交表格后转到客户列表页面。

回答by AntoineB

You should use return redirect()->back();

你应该使用 return redirect()->back();

回答by Gavin

Inside your template file you can just use:

在您的模板文件中,您可以使用:

{{ url()->previous() }}

回答by ka_lin

You have a global backfunction:

你有一个全局返回函数:

return back();

回答by Nikhil Radadiya

Thank You for answers. I've got it now.

谢谢你的回答。我现在明白了。

set the hidden variable in blade to get previous page url using

设置刀片中的隐藏变量以获取上一页 url 使用

{{  Form::hidden('url',URL::previous())  }}

after that get it by $request->input('url');in controller,Then redirect it.

之后$request->input('url');在控制器中获取它,然后重定向它。

return redirect($url)->with('success', 'Data saved successfully!');

回答by El Micke

you should this methods:

你应该这个方法:

return calling controller:

返回调用控制器:

return redirect()->action('classcontroller@fuction');

return calling url:

返回调用网址:

return redirect('home/dashboard');

REDIRECTS LARAVEL 5.2

重定向 Laravel 5.2