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

Laravel访问info.edit路由提示缺少info参数问题求助

问题解决:Laravel路由报错「Missing required parameter for [Route: info.update]」

问题场景

  • 路由配置:
Route::resource('info',InfoController::class);
  • 列表视图的编辑链接:
<a class="btn btn-primary" href="{{ route('info.edit',$info->id) }}" role="button">Update</a>
  • 访问编辑页面URL:http://127.0.0.1:8000/info/36/edit时,抛出错误:

Missing required parameter for [Route: info.update] [URI: info/{info}] [Missing parameter: info]

  • 手动添加路由后仍报错:
Route::get('/info/{info}/edit', [InfoController::class, 'edit'])->name('info.edit');

核心原因

错误提示指向info.update路由,说明问题不在info.edit的GET路由,而是在编辑页面的表单提交配置——你在edit.blade.php里的表单action没有正确传递info参数给update路由。

解决方案

  1. 检查并修正编辑页面的表单代码
    确保表单的action正确调用info.update路由并传入模型ID(或直接传入模型实例,Laravel会自动解析ID):
<form method="POST" action="{{ route('info.update', $info->id) }}">
    @csrf
    @method('PUT') <!-- update路由需要PUT方法,必须添加这行 -->
    <!-- 你的表单输入字段 -->
</form>

或者更简洁的写法(直接传模型实例):

<form method="POST" action="{{ route('info.update', $info) }}">
    @csrf
    @method('PUT')
    <!-- 表单字段 -->
</form>
  1. 删除手动添加的重复路由
    Route::resource已经自动生成了完整的RESTful路由,包括info.edit的GET路由,手动添加会造成路由冲突,直接删掉你额外加的那条路由即可。

  2. 清除路由缓存
    运行以下命令确保路由配置生效:

php artisan route:clear

内容的提问来源于stack exchange,提问作者MR.Dope

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 17:22:50