-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[5.6] Ability to cast model attributes to a specific date format #22989
Conversation
It's unclear from the example, does this also support |
No, |
Is there any particular reason for this? Wouldn't it make sense to support formats on both date and datetimes? (And sure, you can write formats for date that includes times, and formats for datetimes that exclude times. That's just something we'll have to live with.) |
That's the point, use |
I understand that, but there will be people surprised that their format is not working. Why should this work with date, and not with datetime? Can we implement it for both? Is there some limitation in the framework, like is the syntax already taken by something else? Or are we just attempting to surprise developers with "yeah, you can format date as datetimes, but datetimes themselves cannot be formatted"? |
I'm not opposing having |
@themsaid Do you agree that having inconsistent behaviour is a bad thing? If so, why not update the PR to make sure both date and datetime are consistent with one another? |
I'm fine with having |
Updated, now |
what is the best way to set format dynamically, based on user preference? |
@monaye You could add a method to your Model that manipulates the internal PS. This repo isn't for support. Try asking your question on one of the many great community support areas that will likely give you a better answer more quickly:
|
Sir, with all due respect I have tried to implement this property in my Laravel app which was successful in my local but I am unable to implement it on my server, is there anything we need to do to make this accomplish. |
Given the following casts:
When the model is casted to JSON or array output the attributes will be formatted to the date formats provided by the developer: