2017-06-16 27 views
0

条件,使我的数据库有两个表名为球员和团队,每个表都有competitionIdteamId场,所以我的目标是获得competitionId一队基地的所有球员和teamId队表。它只返回一个空数组。Laravel加入与在内部不工作

public static function getTeamRoster($competitionId, $teamId) { 
     return DB::table('teams as team') 
       ->where('team.competitionId', $competitionId) 
       ->where('team.teamId', $teamId) 
       ->join('players as player', function($join){ 
        $join->on('team.competitionId', '=', 'player.competitionId') 
         ->where('player.teamId', 'team.teamId'); 
       }) 
       ->get(); 
    } 
+0

,因为在你的代码,它说'WHERE player.teamID =“团队。 teamID''我想你想'WHERE player.teamID = 1'。对? – aldrin27

+1

在连接链接' - > on()'而不是尝试使用' - > where()'。 – Ohgodwhy

回答

1

尝试以下方法修改其功能是否带给你预期的结果,如果不是请具体谈谈您的要求,

public static function getTeamRoster($competitionId, $teamId) { 
    return DB::table('players AS player') 
     ->join('teams AS team','player.teamId','=','team.teamId') 
     ->where('team.competitionId', $competitionId) 
     ->where('team.teamId', $teamId) 
     ->get(); 
}