Courses

Laravel 11 Eloquent: Expert Level

touch() Method To Work With updated_at

Summary of this lesson:
- Using touch() to update timestamps
- Applying touch() to multiple models
- Managing relationship timestamps
- Controlling automatic timestamp updates

A "quick tip" lesson. Laravel has a few helper methods to update your Eloquent Model updated_at timestamp. For example, on the user Model, you have some users, and you want to update just its updated_at value without touching any other data.

You can use touch() on the Model, which will update only the updated_at field.

Since Laravel 9.25, there's a possibility to use touch() on multiple models with Eloquent query.

Records with an ID bigger than two will be updated, and the result is how many records are updated. In this example, two.


You can also touch a...

The full lesson is only for Premium Members.
Want to access all 28 lessons of this course? (71 min read)

You also get:

  • 69 courses (majority in latest Laravel 11)
  • Premium tutorials
  • Access to repositories
  • Private Discord