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

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -