Laravel查询如何连接多个表中的数据



需要帮助才能在laravel查询中联接多个表

Matches table   
id
round
league_id
home_team_id
away_team_id
match_date

Match facts table   
id
match_id
player_id
minutes
goals

这个查询将主客场球员聚集在一起:

$MatchFacts = Match_fact::where('match_id', $match->id)
->get();

我们的目标是让队员们掌握所有比赛事实。

使用此查询解决的问题:

$away_team_facts = DB::table('match_facts')
->where('match_id', $match->id)
->join('players', 'match_facts.player_id', '=', 'players.id')
->where('players.team_id', '=', $awayTeamId)
->get();

最新更新