Php 在Laravel更新查询中使用数组
我想在Laravel Update Query的Where子句中推送一个数组 这是更新查询Php 在Laravel更新查询中使用数组,php,mysql,sql,laravel-5,Php,Mysql,Sql,Laravel 5,我想在Laravel Update Query的Where子句中推送一个数组 这是更新查询 DB::table('users')->where('id', 1)->update(array('votes' => 1)); 是否可以使用如下查询 $array_of_ids; DB::table('users')->where($array_of_ids)->update(array('votes' => 1)); 谢谢只需使用,其中: $array_of_i
DB::table('users')->where('id', 1)->update(array('votes' => 1));
是否可以使用如下查询
$array_of_ids;
DB::table('users')->where($array_of_ids)->update(array('votes' => 1));
谢谢只需使用
,其中
:
$array_of_ids;
DB::table('users')->whereIn('id', $array_of_ids)->update(array('votes' => 1));
请仔细阅读文档。在这种情况下,这里记录了所有类型的
,其中语句:使用查询生成器:查询生成器还可以使用更新方法更新现有记录。update方法与insert方法一样,接受包含要更新的列的列和值对数组。可以使用where子句约束更新查询:
DB::table('users')
->where('id', 1)
->update(['votes' => 1]);
使用其中
更新Ethanks@lukasgeiter。但此查询也会更新另一个包含日期时间数据的字段。您确定吗?我很确定这个查询应该有效。具体更新了什么?查询正在工作,但它也会更新另一个包含datatime数据的字段。听起来您可能已经设置了数据库字段,以便在自动插入/更新时设置当前时间。。。