Laravel中的增量列 [英] Increment columns in laravel
本文介绍了Laravel中的增量列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在laravel中是否可以增加一个以上的列?
Is there a way to increment more than one column in laravel?
让我们说:
DB::table('my_table')
->where('rowID', 1)
->increment('column1', 2)
->increment('column2', 10)
->increment('column3', 13)
->increment('column4', 5);
但这导致:
Call to a member function increment() on integer
我只想找到一种有效的方法来使用laravel中的给定功能.谢谢.任何建议都可以.
I just want to find an efficient way to do this using the given functions from laravel. Thanks. Any suggestions will do.
推荐答案
没有现成的函数可以执行此操作.您必须使用update()
:
There is no existing function to do this. You have to use update()
:
DB::table('my_table')
->where('rowID', 1)
->update([
'column1' => DB::raw('column1 + 2'),
'column2' => DB::raw('column2 + 10'),
'column3' => DB::raw('column3 + 13'),
'column4' => DB::raw('column4 + 5'),
]);
这篇关于Laravel中的增量列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文