Using withoutTimestamps prevents casted dates in model events #48028
Unanswered
jasonvarga
asked this question in
Q&A
Replies: 1 comment
-
Hi! I have the same issue. Has anyone published this discussion as an issue? Maybe you've found a solution? It seems more like a bug to me. I fixed it by adding "created_at" and "updated_at" to the cast array, so that the fields are forced to get cast. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm running into an issue that I'm hoping is just an oversight on my part.
I have an
updated
model event where I need theupdated_at
value:Then elsewhere, I want to save the model without updating the timestamp:
The
foo
attribute gets updated tobar
, and theupdated_at
value doesn't get modified. Great!However in the model event,
$model->updated_at
is just a string like2023-08-11 03:27:38
. It doesn't get cast to a Carbon instance.If I just did
$model->save()
, then theupdated_at
in the model event would be Carbon instance, but of course the updated_at value would also get updated.Here's a full repo if it helps: jasonvarga/laravel-without-timestamps-issue@086e0d0
Is there a way to have the best of both worlds? Be able to update the model without the timestamp, and be able to get the proper attribute in the event?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions