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

Laravel添加帖子至数据库时触发BadMethodCallException错误排查

解决BadMethodCallException:validateRquired不存在的问题

嘿,这个问题其实一眼就能揪出根源——你把验证规则里的required拼写成了rquired(少了一个字母e)!Laravel的验证器找不到这个不存在的规则方法,自然就抛出了BadMethodCallException异常。

因为你是新增title、type、subtype这三个字段后才出现的错误,所以大概率是在给这三个字段添加验证规则时手滑打错了单词,之前功能正常是因为没用到这个错误的规则。

修复步骤:

  • 找到你处理表单验证的代码(可能在控制器的store方法里,或者自定义的请求类中)
  • 检查title、type、subtype字段的验证规则,把拼写错误的rquired改成正确的required

举个错误写法和正确写法的对比:

错误示例:

$validated = $request->validate([
    'title' => 'rquired|string|max:255',
    'type' => 'rquired|string',
    'subtype' => 'rquired|string',
    'cover_image' => 'nullable|image|max:2048',
    'body' => 'required|string',
]);

正确示例:

$validated = $request->validate([
    'title' => 'required|string|max:255',
    'type' => 'required|string',
    'subtype' => 'required|string',
    'cover_image' => 'nullable|image|max:2048',
    'body' => 'required|string',
]);

改完之后再测试创建帖子的功能,应该就能正常运行啦!

内容的提问来源于stack exchange,提问作者KB_Shayan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:51:42