Laravel加入哪里的条件不起作用

时间:2017-06-16 01:47:06

标签: php mysql laravel laravel-5 eloquent

所以我的数据库有两个名为玩家的表和团队,每个表都有 competitionId teamId 字段,所以我的目标是让所有玩家基于competitionId和teamId团队表的团队。它只返回一个空数组。

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();
    }

1 个答案:

答案 0 :(得分: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();
}