我的Laravel路由代码存在什么错误?student/store路由无法正常工作
Laravel路由冲突问题解析
问题代码
Route::get('student/{id}', 'StudentController@show'); Route::post('student/store', 'StudentController@store');
问题原因
student/store 路由几乎无法正常工作,核心原因是路由匹配优先级和可变参数的匹配范围:
- 第一条路由的
student/{id}包含可变参数{id},该参数默认会匹配任意字符串内容 - 当发起
student/store的请求时,路由解析器会优先匹配到第一条路由,把store当作{id}的参数值传入StudentController@show,导致第二条路由永远不会被触发
内容的提问来源于stack exchange,提问作者someone
相关产品推荐
相关产品推荐

