Level 12
Use a callback function like below.
Campaign::with([
'user',
'user.corporation_users' => function ($query) {
$query->has('corporation');
},
'corporation'
])->get();
1 like
I am working with a database that includes four related tables:
The relationships between these tables are as follows:
I am attempting to retrieve campaigns with all related entities eagerly loaded. My current Laravel Eloquent query looks like this:
Campaign::with([
'user',
'user.corporation_users',
'corporation'
])->get();
However, I need to modify this query so that it only retrieves corporation_users that are related to the corporation associated with each campaign.
How can I add a condition to user.corporation_users in this query to achieve this?
Please or to participate in this conversation.