Let’s say you have a photos table with a field view_count
. Every time the photo is shown you want to increment the value of the field. Assuming that you use the route model binding for Photo model, you need to write only one line of code:
public function view( Photo $photo ) { $photo->increment('view_count'); ... }