Posts Learn Components new Snippets new Categories Tags About
/

How to Increment and Decrement Integer Column in Laravel

Learn how to easily increment and decrement your integer column and save your time

Created on Jul 21, 2021

52 views

To increment and decrement an integer column value in Laravel, you can make use of the built-in method available to every Laravel Eloquent or through the DB query builder.

DB Query Builder
Using the DB query builder it would look like below.
DB::table('posts')->increment('count');

DB::table('posts')->increment('count', 10);

DB::table('posts')->decrement('count');

DB::table('posts')->decrement('count', 10);

Laravel Eloquent
The other way is by using the eloquent model.
Post::find(1)->increment('count');

Post::find(1)->increment('count', 10);

Post::find(1)->decrement('count');

Post::find(1)->decrement('count', 10);
new

If you like our tutorial, do make sure to support us with some coffee. We need the juice to write the content during the night 🤙🏻