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

Laravel Backpack使用InlineCreate报Method not allowed错误

问题现象

使用inline_create功能时,模态框内可正常创建条目,但创建完成后无法选中新生成的条目,抛出如下错误:

Method not allowed:该路由不支持POST方法,支持的请求方法为:GET、HEAD。

  • 报错请求URL:http://127.0.0.1:8000/admin/question/fetch/tags
相关配置代码
// 字段配置
$this->crud->addField(
    [
        'label' => "Les mote clé",
        'minimum_input_length' => 0,
        'type'      => 'relationship',
        'name'      => 'tags', // 模型中定义关联的方法名
        'ajax' => true,
        // 'method'                  => 'GET',
        'minimum_input_length' => 0,
        'attribute' => 'name', // 关联模型用于展示的字段
        'inline_create' =>  [ 
            'entity' => 'tag', // 关联实体的单数名称
            'force_select' => true, // 内联创建完成后是否立即选中该条目
            'modal_class' => 'modal-dialog modal-md', // 模态框尺寸配置
            'modal_route' => route('tag-inline-create'), // 内联创建模态框加载路由
            'create_route' =>  route('tag-inline-create-save'), // 内联创建条目提交路由
        ]  
    ]
);

// Question模型关联定义
public function tags()
{
    return $this->belongsToMany(Tag::class, 'question_tags', 'question_id', 'tag_id');
}
故障原因

内联创建条目完成后,组件会自动发起ajax请求拉取最新选项列表,默认使用POST方法,但当前/admin/question/fetch/tags路由仅开放GET、HEAD请求方法,因此请求被拦截,无法拉取到刚创建的标签完成自动选中。

修复方法
  • 取消字段配置中'method' => 'GET'一行的注释,显式指定选项拉取接口使用GET请求,匹配路由的允许方法。
  • 删除字段配置中重复的'minimum_input_length' => 0配置项,避免冗余配置导致参数解析异常。
  • 确认tag-inline-create-save路由已注册为POST类型,该路由负责处理内联创建的表单提交,必须支持POST方法,不要和选项拉取接口的请求方法配置混淆。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.30 18:03:18