0

need help to join more than one table in laravel query

Matches table   

id
round
league_id
home_team_id
away_team_id
match_date


Match facts table   
id
match_id
player_id
minutes
goals

this query gets home and away team players together:

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

the goal is to get all match facts by team players.

Jetz
  • 207
  • 2
  • 4
  • 14

1 Answers1

0

Problem solved with this query:

$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();
Jetz
  • 207
  • 2
  • 4
  • 14