-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom datetime casting works, but not if you define custom format #2655
Comments
Merged
GromNaN
added a commit
that referenced
this issue
Nov 8, 2023
As mentioned in the #2655 issue, casting date types with a custom format did not work properly. So I decided to cover all date types and fix this issue. I tested these date types: - immutable_date - immutable_date with custom formatting - immutable_datetime - immutable_datetime with custom formatting To achieve this goal, I override one of the cases in castAttribute method to handle immutable_date date type. Also, I override transformModelValue method to check if the result is a DateTimeInterface or not for applying defined custom formatting on the Carbon instance and resetting time in a custom date type. In the end, I should say that all date values will be stored in DB as Date type. (not as an object or string anymore) --------- Co-authored-by: Jérôme Tamarelle <jerome@tamarelle.net>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to #2653 casting works now, but not in all cases. When using date casts, you can also define the format in the string format, like this (docs):
When using cast like that, it doesn't work. Without formatting set, it does work as expected:
Here is simple class that can be used for testing:
And to test this run these commands on Tinker:
As you can see the
sold_at
has Carbon object in database, it should be MongoDB\BSON\UTCDateTime. If you remove the:j.n.Y H:i
part from$casts
then it works as expected. Here is tinker output without the date formatting:Originally posted by @apeisa in #2653 (comment)
The text was updated successfully, but these errors were encountered: