I have this query:

$matches = Match::select('matches.*', 'team.name as enemy_name') ->leftJoin('team', 'team.id', '=', 'matches.enemy_team_id') ->where('matches.team_id', '=', $id) ->orWhere('matches.enemy_team_id', '=', $id); if ($request->only_completed == true) { $matches->where('matches.winner', '!=', 0); } 

and I need to make it like:

 where (team_id = $id or matches.enemy_team_id = $id) and matches.winner != 0 

    1 answer 1

      $matches = Match::select('matches.*', 'team.name as enemy_name') ->leftJoin('team', 'team.id', '=', 'matches.enemy_team_id') ->where(function ($query) use ($id) { $query->where('matches.team_id', '=', $id) ->orWhere('matches.enemy_team_id', '=', $id); }); if ($request->only_completed == true) { $matches->where('matches.winner', '!=', 0); }