[5.2] Model casting to any object#11225
[5.2] Model casting to any object#11225bkuhl wants to merge 1 commit intolaravel:5.2from bkuhl:casting-any-object
Conversation
There was a problem hiding this comment.
Expected 1 newline after opening brace; 2 found
|
Wouldn't it be better to just have a |
|
Currently if it's |
|
I think the ability to extend castAttribute with custom cast types would be very helpful, and perhaps a better route to acheive the functionality you are after and offer greater flexibility for others? If a check was made for a custom attribute cast type before both the check of a null value and the getCastType switch, it would be possible to create custom cast types for objects (including null objects), serialzed objects (which are not currenty supported) and any other implementations (binary, CSV, bson etc.) |
There was a problem hiding this comment.
please sort by length
|
👎 |
|
This involves using the application object that eloquent shouldn't know about. |
|
Yeah, we probably won't be able to have access to the container from within Eloquent. Probably the only option I can think of is to simply pass the raw database value into the object just using like One thing I'm wondering about is how do you cast back for storage... like if I do: How do I know what to make |
|
I appreciate the feedback. I did miss this in the implementation, but my thought was that casted objects would need to implement |
The intended functionality of this PR is to provide the ability to cast to any object. A great example of where this would be useful is user settings when they are stored as json in a
users.settingscolumn. Having the json converted to an object allows one to easily define the default values for settings and a streamlined method of accessing these settings.Here's an example:
Currently I'm experiencing an issue with a unit test am I'm unsure how to mock
app(). Thus a test is failing:I'd like to add another assertion or two once I can get passed this issue.