Laravel我添加了morphmany SQLSTATE [42S22]:找不到列:1054“字段列表”中的未知列“ staff.staff_id”

问题描述

我正确存储了数据,但是当我尝试在编辑功能中获取数据时,它显示了此信息 错误

SQLSTATE [42S22]:找不到列:1054“字段列表”中的未知列“ staff.staff_id”(SQL:选择users。*,staffstaff_id作为{ {1}},pivot_staff_idstaffuser_idpivot_user_idstaffstaff_typepivot_staff_type。 }}分别为staff的{​​{1}},rolepivot_rolestaff的{​​{1}}。created_at pivot_created_at上的内部联接staffupdated_at = pivot_updated_atusers其中staffusers在(2)中,{{ 1}}。id = App \ Models \ Investor)

staff

解决方法

您不关注naming conventions,因此您应确定该关系的 foreign key "other key"

 public function staff()
{
    return $this->morphToMany(User::class,'staff','name of table','foreignPivotKey','relatedPivotKey);
}

我不知道您的表列名称,但在您的情况下,可能如下所示:

public function staff()
{
    return $this->morphToMany(User::class,'staffabels','staffabel_id','staff_id')
                ->withPivot(['role'])
                ->withTimestamps();
}

public function investors()
{
    return $this->morphedByMany(Investor::class,'staff_id','staffable_id');
}

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...