I want to increment the calls / views for a blog. In the controller I have the following two lines:
$post->views = $post->views + 1;
$post->save();
I wonder if the update method might be faster?
Another question about incrementing. Is there a Laravel function that can be used to increment?
2
Answers
In my opinion, both writing methods should be equally fast. Here is your second question. You can use
increment()
function.Both methods will be broadly the same,
update()
also callssave()
.From the
EloquentModel
API: