Courses

Laravel 12 Eloquent: Expert Level

touch() Method To Work With updated_at

You're reading a FREE PREVIEW of a PREMIUM course.
Summary of this lesson:
- Using touch() to update timestamps
- Applying touch() to multiple models
- Managing relationship timestamps
- Controlling automatic timestamp updates

Video Version of the Lesson

[Only for premium members]

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 38 video+text lessons of this course? (1 h 34 min)

You also get:

  • 77 courses
  • Premium tutorials
  • Access to repositories
  • Private Discord