【发布时间】:2016-03-28 13:29:10
【问题描述】:
我想将以下 SQL 语句重写为 Eloquent 格式:
SELECT `id`, `pushbadge`, `pushalert`, `pushsound`
FROM `devices`
WHERE `id` IN (1, 2, 3)
AND `status`='active'"
我的想法是
public function getDevicesWithIDs($ids) {
$conditions = array();
foreach($ids as $id) {
$conditions[] = ['id' => $id];
}
var_dump($conditions);
return Device::where($conditions)->get();
}
但这会返回:
SQLSTATE[42S22]: Column not found: 1054
Unknown column '0' in 'where clause'
(SQL: select * from `devices` where (`0` = 1))
【问题讨论】: