How to Increment Multiple Column Values in Laravel 9

Hello Geek, In this article, you will learn how to increment multiple column values in Laravel.

Prior to the current version of laravel, you could only increment or decrement single-column values in Laravel; however, with it release you can now increment or decrement multiple-column values in Laravel.

In the current version of laravel, incrementEach() and decrementEach() are added to Illuminate/Database/Query/Builder.

These methods can be used to increment or decrement multiple column values. In this article, we will use both methods.

Example of a Multiple Column Value increment:

Example of a Multiple Column Value increment:

DB::table('traffic')->where('slug', 'install-laravel-on-ubuntu')->incrementEach([
     'visit' => 1,
     'cost' => 5,
]);

Example of a Multiple Column Value Decrement:

Example of a Multiple Column Value Decrement:

DB::table('traffic')->where('slug', 'install-laravel-on-ubuntu')->decrementEach([
     'visit' => 1,
     'cost' => 5,
]);

All the best nerd.

Leave a Reply