Eloquent – A better way to increment or decrements an int

Laravel has in-built increment() and decrement() functions to increase or decrease a value of the column, by 1 or with the given number. Below are the examples:

That’s it – it will actually run update column + 1 under the hood.

You can specify a second parameter to this function, the amount of increment. The default is 1, but it can be any other number:

The same way, we can use decrement() function:

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 vote
Article Rating
Notify of
Inline Feedbacks
View all comments
DMCA.com Protection Status
Would love your thoughts, please comment.x