Friday, March 17, 2017

Laravel. Nested relations. Conditions from query outside

I have db tables are related to each other in this way: User - MainGoal - SubGoals - Budgets.

User has one MainGoal

MainGoal has many SubGoal

SubGoal has many Budget

Budget table has column user_id.

So my query builder looks like sth like this:

User::with('Maingoal.Subgoals.Budget');

Eventually, I get Budget for each Subgoal. BUT, I want to get budgets for exact users, for users from first query result in particular (User::with....). Is it possible? What do you think?

Thanks for your answers!



via andrew

Advertisement