Posted inphp / Laravel

how to use increment() and decrement() in laravel Eloquent? – laravel increment

Today, We want to share with you laravel increment.In this post we will show you laravel eloquent, hear for laravel collection filter we will give you demo and example for implement.In this post, we will learn about Increment Decrement With Laravel with an example.

Laravel increment or decrement column value example

we will use laravel eloquent increment() for increase value and we will use laravel 6 eloquent decrement() for decrease value of database table.

Laravel Increment and Decrement Example
Laravel Increment and Decrement Example

But Laravel made this task very easy with increment and decrement function.

Increment Example

Example 1:

$client = Client::find($id);

$guests = $client->guests + 1;
$client->update(['guests' => $guests]);

In this example use increment() function to increment column value in Lravel 6.

Example 2:


If you increment 2 then client increment() function in argument set 2.

Example 3:


Decrement Example

Example 1:


Example 2:


Example 1:


Example 2:


You can also achieve this by update query.
Example 1:

   Client::where('id', $id)->update(['guests' => DB::raw('guests + 1')]);

Example 2:

   Client::where('id', $id)->update(['guests' => DB::raw('guests - 1')]);

Decrement a column value Laravel


If you want to customize column decrement value then you can pass the second argument in the decrement() function like below:

Article::find($id)->decrement('guests', 5);
Article::where('id',1)->decrement("guests", 5); 

Increment Or Decrement Without Using Laravel Methods

Increment column value by

Article::where('id', $id)->update(['guests' => DB::raw('guests + 1')]);

Decrement column value by

Article::where('id', $id)->update(['guests' => DB::raw('guests - 1')]);

Increment a column value Laravel


customize column increment value

Article::find($id)->increment('guests', 5);
Article::where('id',1)->increment("guests", 5);  

I hope you get an idea about laravel query builder.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype