【发布时间】:2019-04-20 21:27:43
【问题描述】:
所以我正在尝试从关联数组中的数据准备一个 Eloquent 查询:
/* This works */
$this
->where("email", "me@gmail.com")
->where("is_active", 1)
->update($params);
/* This doesn't work */
$where = [
'email' => "me@gmail.com",
'is_active' => 1
];
foreach ($where as $k => $v) {
$this->where("{$k}", "{$v}");
}
$this->update($params);
我错过了什么吗? 任何帮助表示赞赏。
编辑:查询不会更新数据库中的实体。
Ubuntu 18.10(宇宙墨鱼):4.18.0-17-generic x86_64 位:64 桌面:Gnome 3.30.2 拉拉多克,Laravel 5.8。
【问题讨论】:
-
为什么
$k和$v用引号括起来? -
@dharman 表明我在测试期间尝试了几个版本;)