[9.x] Fix enum casts arrayable behaviour#40885
Conversation
|
I definitely wouldn't expect enums to be converted to their array version. Their value should be used. The current behavior is expected imo. |
|
Without this change there's no point in an enum implementing On the other hand I don't see much of an use case in transforming a scalar value into an array. I guess there's no harm in letting enums behave like all other |
|
@X-Coder264 hmm I guess you're right about that. |
|
If this is considered a bug fix, this should probably land on Laravel 8, not 9. |
|
@GrahamCampbell yes, you're probably right, this PR can ported to 8.x branch with no work at all. However enums are a php 8.1 feature so it's probably more usefull on 9.x branch |
|
PHP 8.1 can also be used with Laravel 8, so that's not relevant, actually. |
|
@taylorotwell Should I make a PR on 8.x branch too, like @GrahamCampbell suggested? |
This PR fix a wrong behavoiur when an attribute is casted to an enum implementig Arrayable in comparision to the behavoiur when the same thing is done on a collection object.
Clarifying example:
Let's take this enum:
Behaviour in a collection object:
Behaviour in a casted model attribute:
Expected behaviour:
Related issues: #40580 and #40693