gpt4 book ai didi

mysql - 我如何从 Blade View 中与 FK 连接的 3 个表中获取值

转载 作者:行者123 更新时间:2023-11-29 06:37:23 25 4
gpt4 key购买 nike

表:项目 enter image description here

表:projects_departments enter image description here表:部门enter image description here

这是模型项目

public function projects_departments() {
return $this->hasMany(Project_department::class);
}

这是模型项目_部门

public function projects()
{
return $this->belongsTo(Project::class);
}

public function departments()
{
return $this->belongsTo(Department::class);
}

这里是模特部

public function projects()
{
return $this->hasMany(Project::class);
}

public function projects_departments() {
return $this->hasMany(Project_department::class);
}

这是我的 Blade

project->departments->department_name

这是我的错误SQLSTATE[42S22]:未找到列:1054“where 子句”中的未知列“projects_departments.project_id”(SQL:从 projects_departments where projects_departments.project_id 选择 * = 48 且 projects_departmentsproject_id 不为空)

最佳答案

$project = DB::table('projects')
->select(*)
->join('Department', 'projects_departments.department_id', '=', 'Department.id')
->join('projects_departments', 'projects_departments.project_id', '=', 'projects.id')

->get();

让我们试试这个

关于mysql - 我如何从 Blade View 中与 FK 连接的 3 个表中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53185383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com