In query I use Nested Eager Loading:
$res = User::where("id", 1)->with("categories.categoryAnn.announcements")->get();
In result of this query I get nested collections:
Collection->User->categories->categoryAnn->announcements
How to shortly get last nested object announcements
?
You can simplify it attempting the following:
The idea or assumption here is that for each categories,
categoryAnn
is one and can haveone-many
announcements.You can do it the opposite way to get only announcements like this:
This is obviously pseudocode, because I don't know exact names of your relationships but something like this should work and you don't need any loops here.