// Simple way without where condition
https://laravel.com/docs/5.7/queries#increment-and-decrement
DB::table('users')->increment('votes');
DB::table('users')->increment('votes', 5);
DB::table('users')->decrement('votes');
DB::table('users')->decrement('votes', 5);You may also specify additional columns to update during the operation:
DB::table('users')->increment('votes', 1, ['name' => 'John']);// Complex way with where condition
https://stackoverflow.com/questions/29816123/increment-columns-in-laravel
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'),
]);
No comments:
Post a Comment