Home / Snippets / How to Increment and Decrement Integer Column in Laravel
How to Increment and Decrement Integer Column in Laravel cover

How to Increment and Decrement Integer Column in Laravel

612

3 years ago

0 comments

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);
notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

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

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this