I have the following models/tables:
branch:
id - integer
department:
id - integer
teacher:
id - integer
branch_department_id - integer
branch_department:
id - integer
branch_id - integer
department_id - integer
- each
branch
has manydepartments
through the pivot tablebranch_department
- each
branch_department
has manyteacher
s
I want to model a hasManythrough
relationship between branch
and teacher
s
so from a specific branch
i want to get all teachers through every branch_department
that is related to that branch
How can I define this?
2
Answers
add branch_department model and:
If you haven’t define a
BranchDepartment
model.From here you can just define the
hasManyThrough
relationship on yourBranch
model.