[英]Laravel whereIn not returning all
节日快乐。 我卡住了! 我在这里和那里涉猎但不是非常精通所以一些帮助将不胜感激。
我在 MySQL 数据库中有一个incident
记录,其中包含字段incident_uid
。 这是包含用户 ID 的逗号分隔字符串。 然后,它会在整个应用程序中展开,形成一个数组,以便在多个用户与事件相关联时查找用户名。
我还有一个scheme_vehicle_log
记录,其中包含一个responders
列 - 同样是一个以逗号分隔的用户 ID 字符串。
我正在尝试运行以下命令,但它没有按预期运行。
$incident_responders = explode(',', $incident->incident_uid);
$schemevehicles = SchemeVehicleLog::whereIn('responders', $incident_responders)
->whereDate('signout_date', '<=', $incident->incident_date)
->where(function ($q) use ($incident) {
$q->where('return_date', '>=', $incident->incident_date)
->orWhere('return_date', null);
})
->get();
它要么只返回一些行,要么根本不返回。 dd($incident_responders)
按预期确认数组。
array:2 [▼ // app/Http/Controllers/IncidentController.php:63
0 => "97"
1 => "17"
]
但是dd($schemevehicles)
显示为空。
如果我用 [97,17] 替换$incident_responders
$schemevehicles
查询中的 $incident_responders,我会得到预期的结果。
在过去的一个小时里尝试过,并认为这将是非常简单的事情——我在这里忽略了什么?
谢谢两位。
我设法找到了问题所在。 dd($incident_responders) 以字符串类型返回数据,而不是 integer,因此查询失败(“97”而不是 97)。 添加 array_map 有帮助。
谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.