[5.5] Added custom attribute types #21419
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For the ability to create custom cast mutators.
In 5.5, a lot of model functionality was transferred to concerns (traits) removing the ability to override various methods in other traits.
This feature provides the ability to override existing casts built-in to Laravel, or define your own using similar naming convention used elsewhere in Laravel.
For example, we have a UUID attribute that is stored as binary in the database. When we use this value though, we need it cast as a string. Currently we would have do this with a defined mutator on each model.
This update would allow us to define a mutator in a trait that we apply to models that have this field. We would create a
castUuidValue
method which takes a value, mutates, and returns the value. In the UUID case we would convert the binary value into a string.In my personal cases, I use packages for both UUID and JSON cast types which no longer work in 5.5 due to the method collision from the new traits.