多个可选参数不适用于laravel 5.3路由

哈比卜

我在web.php中有以下路由,第一个路由始终有效,但是如果我使用url,第二个路由则无效

ads/mobiles

然后函数check_if_category执行正常。但是我像这样使用url

ads/lahore/mobiles

在这种情况下,它将重定向到404页面。

Route::get('ads/all', 'AdControllerWithoutAuth@all_ads')->name('route_all_ads');
Route::get('ads/{location?}{category?}{keyword?}', 'Categories@check_if_category')->name('route_f_category_page');

我也这样工作

Route::get('ads/all', 'AdControllerWithoutAuth@all_ads')->name('route_all_ads');
//Route::get('ads/{location?}', 'Categories@check_if_category')->name('route_f_category_page');
//Route::get('ads/{location?}{category?}', 'Categories@check_if_category')->name('route_f_category_page');
Route::get('ads/{location?}{category?}{keyword?}', 'Categories@check_if_category')->name('route_f_category_page');

但没有成功。预先感谢您的帮助。

耶罗杰夫

您需要/在这些参数之间添加,否则Laravel会将它们视为一个长字符串。

Route::get('ads/{location?}/{category?}/{keyword?}', 'Categories@check_if_category')->name('route_f_category_page');

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章