【发布时间】:2021-10-27 09:33:55
【问题描述】:
假设我有一个如下的数据库架构:
Department -> id | department_name
Employee -> id | department_id | name
Attendance -> id | employee_id | timestamp
我可以使用hasManyThrough 关系从Department 模型中检索部门的所有出勤率,如下所示:
public function attendance() {
return $this->hasManyThrough(EmployeeAttendance::class, Employee::class, 'department_id', 'employee_id', 'id', 'id');
}
但是,我试图做相反的事情,即从考勤模型中检索员工的部门。我曾尝试使用hasOneThrough 关系,但我无法得到它。我已经查看了文档以及其他相同的教程。任何关于如何通过Attendance 模型中的关系来帮助我的帮助将不胜感激。
【问题讨论】:
标签: laravel eloquent has-one-through