Adding a $touchesOnCreate property to Eloquent Models #51368
Unanswered
EdenMitchell
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The
$touches
property on Eloquent Models is great for ensuring parent models are updated whenever their children are updated. However, I've encountered a few occasions now where I want to update the parent model only when the child is created. Right now I'm using model events to update the parent on creation, which is fine, but I've been thinking about a$touchesOnCreate
property...Let's look at the example from the Laravel docs on
$touches
, where a Comment touches a Post. There could be a valid use case right there. If I'm showing a list of Posts ordered by updated_at descending, I don't necessarily want a post appearing at the top of the list because someone just edited their comment from last month. Or perhaps I do want it appearing at the top? Both approaches are completely valid product decisions, hence the idea behind adding$touchesOnCreate
.I'm happy to make a PR and see how I go, but I'm curious if I'm missing anything obvious or if I'm the only person who ever runs into this use case? Or... if this is a reasonable idea, is there a more suitable approach than adding a
$touchesOnCreate
property?Beta Was this translation helpful? Give feedback.
All reactions