Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

touch() Method To Work With updated_at

Premium
3:47

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

AG
Alex Gower ✓ Link copied!

Thanks! This concept has become more important to me when I have been indexing data using scout to rebuild the document

MJ
Manuel Jacquez ✓ Link copied!

Hi there! I have tried this on a "normal" haveMany/belongsTo relationship, lets say Post has many Comment and it works fine, but when the relationship is a Morph relationship (using model_id and model_type fields), it doesnt seem to work... documentation doesnt say anything about touching timestamps in morph relationships. I solved that "manually" with model events but i dont know if iI'm missing something when trying to touch timestamps in a morph. how do you indicate the parent model? protected $touches = ['model']

PK
Povilas Korop ✓ Link copied!

I've never used it in a Morph relationship, I don't think it would work, I also haven't seen it in the docs. So you were right to build it manually with Events.