[5.4] Add Caster Classes#16460
[5.4] Add Caster Classes#16460faustbrian wants to merge 1 commit intolaravel:masterfrom faustbrian:master
Conversation
DuckThom
left a comment
There was a problem hiding this comment.
as Is a reserved keyword in php and cannot be used as function name.
|
This is essentially similar to the original model cast PR I already submitted. We may re-open that one if interest continues. |
|
@taylorotwell I believe this approach is a bit different to your proposal #13706. In your proposal we can only cast attributes into objects whereas with this alternative we can use it to transform attributes to whatever value we want. For example, decoding from base64 string #16450. It will be up to the developer to take care of value objects if that's what they need/want; but this PR is not about casting attributes into objects, it's more generic. |
|
@JosephSilber, I think this gives us the freedom we needed. |
|
@taylorotwell As @CristianLlanos pointed out this implementation is kept quite generic and opposed to your PR this leaves the developer free hand as to what he wants to do with the value passed to the caster. I guess you could describe this implementation more as a generic transformer for model attributes. |
|
@CristianLlanos Moved the PR to a package https://github.com/faustbrian/Eloquent-Castable. Maybe this will find it's way into Laravel one day. |
This makes use of classes for casting models instead of using a switch statement for each single type to perform some action on the value.