Posts Learn Components Snippets Categories Tags Tools 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

266 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);

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

new

PostSrc Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that are right for your project.

View Components
)