因此,我的数据库中有两个名为玩家和球队的表,每个表都有CompetitionId和teamId字段,因此我的目标是根据teams表的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();
    }

最佳答案

请尝试使用以下修改后的功能,是否会带来预期的效果,如果没有,请更详细地说明您的要求,

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

10-08 05:05