0

I want to update documents and decrement specific column value. it is possible to use Model::where('','')->update(['count' => \DB::raw('count- 1')]); i'm using jenssegers/laravel-mongodb package.

I want decrement and update documents values together.

$result= Source::where('')
         ->where('');
$result->decrement('count');
$result->update([
   'column' => true,
]);

This code decrement count value but can not update column values.

Ali Raza
  • 670
  • 5
  • 15

2 Answers2

0

From the docs:

Perform increments or decrements (default 1) on specified attributes:

Cat::where('name', 'Kitty')->increment('age');

Car::where('name', 'Toyota')->decrement('weight', 50);
Tymur Valiiev
  • 637
  • 9
  • 25
0

i found it from laravel doc updated column value pass 3rd parameter as array in decrement method

Model::where('', null)
        ->where('', '')
        ->decrement('count', 1, [
            'column1' => value1,
            'column2' => value2,
            'column3' => value3,
        ]);
Ali Raza
  • 670
  • 5
  • 15