gpt4 book ai didi

php - Laravel Join 中的 where 条件不起作用

转载 作者:行者123 更新时间:2023-11-29 10:45:53 26 4
gpt4 key购买 nike

所以我的数据库有两个名为players和teams的表,每个表都有competitionIdteamId字段,所以我的目标是获取所有玩家基于团队表的竞赛 ID 和团队 ID 的团队。它只返回一个空数组。

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

关于php - Laravel Join 中的 where 条件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44579572/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com