Eloquent: incrementing columns without update() function
Tutorial last revisioned on August 18, 2022 with Laravel 9
Eloquent mechanism isn't limited to just create/update/delete functions - that's why it's awesome. One of those helpers come to rescue when you need to increment a column, basically run update X set Y=Y+1 where id = Z - apparently, there's no need to run update() function for that.
A straightforward way of doing this is get the row, make the calculation and update the row, like this:
That's it - it will actually run update column + 1 under the hood.
And not only that, you can specify a second parameter to this function: the amount of incrementing. The default is 1, but it can be any other number:
nice