我是 Laravel 的新手,正在学习 leftJoin。
我有一个名为“users”的表,其中行为“steam_id”。
我有另一个名为“匹配”的表。 “匹配”表有一个名为的唯一行 “match_id”。
最后一张名为“match_players”的表也有名为“match_id”和“steam_id”的行。 “match_id”与表行“matches -> match_id”相同。
我需要通过使用用户 steam_id 和比赛中的 match_id 来获取信息。
Controller :
$user->LatestMatches = DB::table('match_players AS mp')
->leftJoin('matches AS ma', 'ma.match_id', '=', 'mp.match_id')
->where('mp.steam_id', '=', $user->steam_id)
->where('team', '=', 2)
->where('team', '=', 1)
->select("mp.*", "ma.map")
->get('');
Blade :
@foreach ($user->LatestMatches as $lastmatch)
{{ $lastmatch->map }}
@endforeach
但没有得到任何信息。抱歉,如果您不明白我需要做什么。感谢您的回复并帮助我理解 Laravel!
最佳答案
->where('team', '=', 1)->where('team', '=', 2)
不起作用,因为它选择的玩家位于 team 1
和 team 2
同时进行。没有玩家可以满足这个限制。
使用 ->whereIn('team', [1, 2])
代替。这会选择team 1
ORteam 2
中的玩家。
关于php - Laravel leftJoin 现在显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51446403/