eloquent - Eager loading with conditional - Laravel -
i have query:
$tournament = tournament::with( 'championships', 'championships.settings', 'championships.category', 'championships.tree.users', )->first();
right now, gives me tournament attached championships.
what need tournament championship match $request->championshipid have.
off course, want filter in other relations ('championships.settings', 'championships.category','championships.tree.users') idea?
you can use constraining eager loading
this:
$tournaments = tournament::with(['championships' => function ($query) { $query->where('something', 'like', '%this%'); }, 'championships.settings' => function ($query) { $query->where('something', 'like', '%this%'); }, ...])->get();
hope helps!
Comments
Post a Comment