Reputation: 893
How to get relationship of the pivot table with eloquent.
$questions = Question::with('teams')->get();
This gets me the list of all questions along with teams.Now i need to get the list of players in any particular team.
Relation in Team Model.
public function players()
{
return $this->hasMany(Player::class,'player_id');
}
Upvotes: 0
Views: 691
Reputation: 768
You can get the nested relation by using the following:
$variable = Question::with('teams.players')->get();
You can find more information on nested relationships here: https://laravel.com/docs/5.4/eloquent-relationships#eager-loading
Upvotes: 1