Vainglory07 Vainglory07 - 1 year ago 102
MySQL Question

Increment columns in laravel

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

Let's say:

->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.

Answer Source

There is no existing function to do this. You have to use update():

   ->where('rowID', 1)
       'column1' => DB::raw('column1 + 2'),
       'column2' => DB::raw('column2 + 10'),
       'column3' => DB::raw('column3 + 13'),
       'column4' => DB::raw('column4 + 5'),