PHP Laravel 5.5 belongsToMany multi-table query table duplicate problem

the name of the operator (that is, the name of the recorder) when the employee under the department is added through the department multi-table.

existing

one 
    one_id
    tow_idID
tow
    tow_idID
    name  
    tows_id(IDID)

SQL

select c.name from one as a join tow as b join tow as c where a.one_id = 1 a.tow_id = b.tow_id and b.tows.id = c.tow_id;

Please give me some advice on how to write laravel belongsToMany. Thank you!

Mar.28,2021

there is something wrong with the construction of your table. Which employee's id is recorded in the id, of the subtable in the main table? it should be the field of department id added to the employee table. Then the department can belongsToMany employees.

Menu