Laravel9中如何修改web.php里的Resource路由URL?
正确实现代码
要生成以fun_student为前缀的目标URL,直接将Route::resource的第一个参数设置为fun_student即可,无需额外使用prefix分组:
// web.php Route::resource('fun_student', StudentController::class);
生成的路由列表说明
执行php artisan route:list后,会得到符合需求的路由:
GET|HEAD fun_student ................ fun_student.index › StudentController@index POST fun_student ................ fun_student.store › StudentController@store GET|HEAD fun_student/create ......... fun_student.create › StudentController@create GET|HEAD fun_student/{fun_student} ... fun_student.show › StudentController@show PUT|PATCH fun_student/{fun_student} .. fun_student.update › StudentController@update DELETE fun_student/{fun_student} . fun_student.destroy › StudentController@destroy GET|HEAD fun_student/{fun_student}/edit .. fun_student.edit › StudentController@edit
之前尝试的问题说明
- 第一次用
prefix('fun_fun_student')搭配resource('students'),会生成fun_fun_student/students这类URL,和目标不符; - 第二次用
resource('fun')只会生成fun开头的URL,不是你需要的fun_student。
内容的提问来源于stack exchange,提问作者bluetail
相关产品推荐
相关产品推荐

