[英]Can I omit optional parameter in laravel routing?
here's code: 这是代码:
Route::get('diagram', 'DiagramController@showDiagram');
Route::get('diagram/{type}', 'DiagramController@showDiagram');
Route::get('diagram/{type}/{template}', 'DiagramController@showDiagram');
Route::get('diagram/{type}/{template}/{offset}', 'DiagramController@showDiagram');
and here's how I want it to look like: 这就是我想要的样子:
Route::get('diagram/{type}/{template}/{offset}', 'DiagramController@showDiagram');
Is there a way to tell Laravel that all of the above parameters don't have to be given in url? 有没有办法告诉Laravel以上所有参数都不必在url中给出? Or do I have to declare it like above in four lines?
还是我必须像上面四行那样声明它?
You don't have to write four line for that, check the Routing documentation on Laravel. 您不必为此写四行,请查看Laravel上的Routing文档 。
So in your case, you could write 所以在你的情况下,你可以写
Route::get('diagram/{type?}/{template?}/{offset?}', 'DiagramController@showDiagram');
You just add a ?
您只需添加一个
?
at the end of each optional parameters. 在每个可选参数的末尾。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.