$tournaments = Tournament::has('games.plays')->get();
Sep 21, 2016
4
Level 6
Retrive deep relation
Hi, I have three tables in my DB. Tournaments, Games and Plays. One Tournament have multiple Games, one Game belongs to one Tournament, one Game have multiple Plays, and one Play belongs to one Game. In store tournament_id in Game table and game_id in Plays table. I try sth like this,
Tournament::find(1)->games->plays
but it doesnt worked. Relation hasManyThrough() is not solution for me either.
Which way is the best to get tournament with games an plays ?
Level 122
Eager loading (with)
$tournament = Tournament::with('games.plays')->find(1);
then, eg in blade view
@foreach($tournament->games as $game)
<h2>{{ $game->title }}</h2> // or name or whatever
// details about game
@foreach($game->plays as $play)
<h3>{{ $play->title }}</h3> //or name or whatever
//details of play
@endforeach
@endforeach
1 like
Please or to participate in this conversation.