Eager loading with conditional - Laravel
Load the relations in the subquery constraint:
$tournament = Tournament::with(['championships' => function($query) use ($request) {
return $query->where('id', $request->championshipId)
->with([
'settings',
'category',
'tree.users'
]);
}])->first();
You can use Constraining Eager Loading
like this:
$tournaments = Tournament::with(['championships' => function ($query) {
$query->where('something', 'like', '%this%');
},
'championships.settings' => function ($query) {
$query->where('something', 'like', '%this%');
},
...])->get();