@@ -647,6 +647,29 @@ public function increment($column, $amount = 1, array $extra = [], array $option
647
647
return $ this ->performUpdate ($ query , $ options );
648
648
}
649
649
650
+ public function incrementEach (array $ columns , array $ extra = [], array $ options = [])
651
+ {
652
+
653
+ $ query = ['$inc ' => $ columns ];
654
+
655
+ if (! empty ($ extra )) {
656
+ $ query ['$set ' ] = $ extra ;
657
+ }
658
+
659
+ // Protect
660
+ foreach ($ columns as $ column => $ amount ) {
661
+ $ this ->where (function ($ query ) use ($ column ) {
662
+ $ query ->where ($ column , 'exists ' , false );
663
+
664
+ $ query ->orWhereNotNull ($ column );
665
+ });
666
+ }
667
+
668
+ $ options = $ this ->inheritConnectionOptions ($ options );
669
+
670
+ return $ this ->performUpdate ($ query , $ options );
671
+ }
672
+
650
673
/**
651
674
* @inheritdoc
652
675
*/
@@ -655,6 +678,17 @@ public function decrement($column, $amount = 1, array $extra = [], array $option
655
678
return $ this ->increment ($ column , -1 * $ amount , $ extra , $ options );
656
679
}
657
680
681
+ public function decrementEach (array $ columns , array $ extra = [], array $ options = [])
682
+ {
683
+ $ decrement = [];
684
+
685
+ foreach ($ columns as $ column => $ amount ) {
686
+ $ decrement [$ column ] = -1 * $ amount ;
687
+ }
688
+
689
+ return $ this ->incrementEach ($ decrement , $ extra , $ options );
690
+ }
691
+
658
692
/**
659
693
* @inheritdoc
660
694
*/
0 commit comments