laravel 从laravel中的url获取参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26993125/
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
get parameters from url in laravel
提问by Lucas Campos
I have some filters on my view and I want to get the parameters of my current URL and do something like edit any of my items in the page and go back with all the filters again after edit.
我的视图中有一些过滤器,我想获取当前 URL 的参数并执行一些操作,例如编辑页面中的任何项目并在编辑后再次返回所有过滤器。
My example URL:
我的示例网址:
localhost:8000/equipamentos/filtro?filter_descricao=APARELHO+ULTRASSOM&filter_patrimonio=0
本地主机:8000/equipamentos/filtro?filter_descricao=APARELHO+ULTRASSOM&filter_patrimonio=0
Then I choose any item to edit and go to:
然后我选择要编辑的任何项目并转到:
localhost:8000/equipamentos/332/edit
本地主机:8000/equipamentos/332/edit
After I change something I want to be redirected to the same URL with the filters in the beginning, like redirect and append filtro?filter_descricao=APARELHO+ULTRASSOM&filter_patrimonio=0
在我更改某些内容后,我想在开始时使用过滤器将其重定向到相同的 URL,例如重定向和附加 filtro?filter_descricao=APARELHO+ULTRASSOM&filter_patrimonio=0
Thanks!
谢谢!
回答by Nabil Kadimi
Use the Input facade:
使用输入门面:
// All
$data = Input::all();
// $_REQUEST['foo']
$data = Input::get('foo'); // null if foo doesn't exist
$data = Input::get('foo', 'bar'); // if foo doesn't exist, the value is bar
Then you can handle the redirection in the controller on in a filter.
然后您可以在过滤器中处理控制器中的重定向。
回答by Pete Houston
I just drafted out the code and it is working.
我刚刚起草了代码,它正在工作。
Route::get('/query', function() {
return Redirect::route('result', Input::query());
});
Route::get('/result', [ 'as' => 'result', 'uses' => function() {
return Response::make(Input::all());
}]);
Either Input::all()
or Input::query()
should work to retrieve GET
parameters.
要么Input::all()
或Input::query()
应该努力检索GET
参数。
I'm using Laravel 4.2.11
我正在使用 Laravel 4.2.11