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
 

2 weeks ago

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)

ServerAvatar
Multiple sites on a single VPS/VM/Server Deploy PHP sites on cloud in minutes, simple as that!
ServerAvatar
Generate Free SSL Certificate - SSLForWeb

Generate Free SSL Certificate

  • 90-Day Certificates
  • SSL Monitoring
  • Wildcard Certificates
  • Multiple Domains
  • Certificate Management
  • Expiration Reminders

Comment


Note: All Input Fields are required.