How to Increment Multiple Column Values in Laravel 9 - TechvBlogs

How to Increment Multiple Column Values in Laravel 9

In this article, You will learn How to Increment Multiple Column Values in Laravel.


Suresh Ramani - Author - TechvBlogs
Suresh Ramani
 

1 year ago

TechvBlogs - Google News

Before Laravel v9.48.0 you can only increment or decrement single-column values in Laravel but after this v9.48.0 release, you can increment or decrement multiple-column values in Laravel.

Laravel v9.48 introduce incrementEach() and decrementEach() to Illuminate/Database/Query/Builder.

You can use those methods to increment or decrement multiple column values. We will use both methods in this article.

How to Increment Multiple Column Values in Laravel 9

Increment Multiple Column Value Example:

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

How to Decrement Multiple Column Values in Laravel 9

Decrement Multiple Column Value Example:

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

That's it.

Thank you for reading this article.

Read Also: Add Column After A Column In Laravel Migration

Comments (0)

Comment


Note: All Input Fields are required.