在Laravel 5.0中隐藏路线的必需参数 [英] Hide required parameters of routes in Laravel 5.0
问题描述
如何在laravel 5中隐藏获取路线的参数?
How could i hide the parameters of a get route in laravel 5?
我的意思是,一条路线可以具有必需的参数,也可以具有可选的参数,我想知道如何隐藏这些参数.
I mean, a route can have required parameters, and also optional parameters, i would like to know how to hide that parameters.
您可以在路由中捕获请求URI的分段:
You can capture segments of the request URI within your route:
Route::get('user/{id}', function($id)
{
return 'User '.$id;
});
如果我的域名为:example.com,则当我访问 example.com/user/201348 时,我希望在浏览器中输入的网址为: example.com/user .
If my domain is: example.com, when i access to example.com/user/201348 i would like that in the browser the URL be: example.com/user for example.
推荐答案
您需要的不是获取路线,而是发布路线.
What you need is not a get route but a post route.
Route::get('user/', function(Request $request)
{
return 'User '.$request->get('id');
});
但请记住: 您需要创建一个表单以生成发布请求.
But keep in mind: You need to create a form to generate a post request.
{{ Form::open(array('url' => 'user')) }}
{{ Form::hidden('id', $userId); }}
{{ Form::submit('Show user with id '.$userId); }}
{{ Form::close() }}
这篇关于在Laravel 5.0中隐藏路线的必需参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!