路由冲突另一种解决方式(正则表达式约束)
//restful 查看
Route::get('products/{product}', 'ProductsController@show')->name('products.show');
//收藏
Route::get('products/favorites', 'ProductsController@favorites')->name('products.favorites');
教程中给出的一种解决方式是将两个路由的位置进行上下调整,当项目变的越来越大,路由增多后,这样的操作可能会给后期挖坑
所以建议增加where条件限制
//restful 查看,product仅支持数整,当id规则变更后,只需更改正则条件
Route::get('products/{product}', 'ProductsController@show')->name('products.show')->where(['product' => '[0-9]+']);
个人建议使用where方式
本帖已被设为精华帖!
本帖由系统于 5年前 自动加精
好方法,學習了。
学到了
get
我以前经常遇到这个问题,只能改名字!现在学到了!谢谢了
可以 不错!
这个方法值得一个点赞