使用 Eloquent (Laravel 5.4) 更新多条记录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42863232/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:35:40  来源:igfitidea点击:

Updating Multiple Records using Eloquent (Laravel 5.4)

laraveleloquent

提问by Alex

I have the following query that is working but I'm wondering what the Eloquent ORM equivalent would be?

我有以下正在运行的查询,但我想知道 Eloquent ORM 的等价物是什么?

       DB::table('exercises')->whereIn('id', $ids)->update($request->all());

Thanks

谢谢

回答by Alexey Mezenin

Eloquent equivalent is almost the same:

Eloquent 等价物几乎相同:

Exercise::whereIn('id', $ids)->update($request->all());

回答by Chandan Sharma

Here, $ids = [1,2,3];

这里,$ids = [1,2,3];

DB::table('users')
   ->whereIn('id', $ids)
   ->update(array('active' => true));

By using the above query we can update multiple rows same time.

通过使用上面的查询,我们可以同时更新多行。