在Laravel更新查询中使用数组 [英] Use an array in Laravel update query

查看:68
本文介绍了在Laravel更新查询中使用数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Laravel更新查询的 Where子句中推送一个数组.

I would like to push an array in Where Clause of Laravel Update Query.

这是更新查询.

DB::table('users')->where('id', 1)->update(array('votes' => 1));

是否可以使用下面的查询?

Is it possible to use the query like below ??

$array_of_ids;
DB::table('users')->where($array_of_ids)->update(array('votes' => 1));

谢谢

推荐答案

只需使用 whereIn :

$array_of_ids;
DB::table('users')->whereIn('id', $array_of_ids)->update(array('votes' => 1));

请仔细阅读文档.在这种情况下,此处记录了各种 where 语句:查询生成器-选择

Please read the documentation carefully. In this case, all kinds of where statements are documented here: Query Builder - Selects

这篇关于在Laravel更新查询中使用数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆