Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

moh_abk's avatar

Has Many Through relationship

My DB setup is like this; Each of the tables has a one-to-many relationship with the next table.

Table 1 (one2many) Table 2 (one2many) Table 3 (one2many) Table 4

In the eloquent docs it says you can use the hasManyThrough to access distant relationships.

Is it possible to have a single eloquent query that will transverse 4 tables and get all the data using hasManyThrough? Basically I want a single query to get an item from Table1 get the matching items in Table2 then the items in Table2 will get their matching items in Table3 and so on and so on.

Using the below I can get parent and child or vice versa;

$parent = ParentModel::with('children')->get();
0 likes
0 replies

Please or to participate in this conversation.