You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 04:12:38