Home > OS >  increment or decrement without using laravel methods mangodb jassengers
increment or decrement without using laravel methods mangodb jassengers

Time:07-25

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.

CodePudding user response:

updated column value pass 3rd parameter as array in decrement method

Model::where('', null)
        ->where('', '')
        ->decrement('count', 1, [
            'column1' => value1,
            'column2' => value2,
            'column3' => value3,
        ]);

CodePudding user response:

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);
  • Related