Add casting closures in eloquent models #52494
-
I was experimenting with some cool features in Laravel and noticed that one of my columns is storing multiple types of data, with the data type being stored in another column. I realized that I need to cast the data according to the type specified in that other column. I found that we can only use the I wanted to suggest that it might be useful if Laravel allowed us to use closures for casting attributes for simpler cases where we don’t need to do much beyond parsing the data type. This would provide a more streamlined approach for small, straightforward casting needs. What do you think? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
InboundAttributes style? |
Beta Was this translation helpful? Give feedback.
-
Additionally, there could be a |
Beta Was this translation helpful? Give feedback.
When the database looks like this:
Then, the model will look like this: