Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is there a way to increment more than one column in laravel?

Let's say:

DB::table('my_table')
->where('rowID', 1)
->increment('column1', 2)
->increment('column2', 10)
->increment('column3', 13)
->increment('column4', 5);

But this results to:

Call to a member function increment() on integer

I just want to find an efficient way to do this using the given functions from laravel. Thanks. Any suggestions will do.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
391 views
Welcome To Ask or Share your Answers For Others

1 Answer

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'),
   ]);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...