Hide required parameters of routes in Laravel 5.0

半腔热情 提交于 2019-12-25 07:05:25

问题


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.

Here's Laravel docs for Route parameters

You can capture segments of the request URI within your route:

Route::get('user/{id}', function($id)
{
    return 'User '.$id;
});

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.


回答1:


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() }}


来源:https://stackoverflow.com/questions/32076500/hide-required-parameters-of-routes-in-laravel-5-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!