php - Laravel leftJoin 现在显示结果

标签 php mysql laravel

我是 Laravel 的新手,正在学习 leftJoin。

我有一个名为“users”的表,其中行为“steam_id”。

我有另一个名为“匹配”的表。 “匹配”表有一个名为的唯一行 “ma​​tch_id”。

最后一张名为“ma​​tch_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 1ORteam 2中的玩家。

关于php - Laravel leftJoin 现在显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51446403/

相关文章:

java - facebook api(java或php): how to request the user to add the application when he opens it?

php - mysql中如何连接三个表?

PHP 复选框检索数据

mysql - 为什么 MySQL 与 SQLServer 的工作方式不同,允许使用 GROUP BY 子句的多列

php - 如何在 PHP 中从 MySQL 数据库下载基于 blob 的文件?

php - 获取引用对象的数据

mysql - 使用 postgreSQL 在 Heroku 中托管 Laravel 项目时出现错误

php - 从 php 检索数据库权限?

php - 基于 HTML 中设置的数据过滤器构建通用 PHP/MySQL 查询

php - 在 PHP 中处理多个(未)选中的复选框的最简单和最干净的方法