-
-
Notifications
You must be signed in to change notification settings - Fork 893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Laravel] Model property casting to Enum is not working #6906
Comments
When you cast something as an enum, Laravel does the transformation for you, but in the database it is still a string, hence it is working when you remove the cast since it is only string. When you have the cast enabled, the string is automatically converted back to you enum by laravel on read operations. Now API Platform tries to normalize it, but does not know how since there is no backed enum normalizer, see here. Since Symfony now also comes with a BackedEnumNormalizer, i think it is fine to add it. I will open a PR and we will see. But in the meantime you can archive this yourself by putting this into your AppServiceProvider:
|
Closes: api-platform#6906 Signed-off-by: Tobias Oitzinger <[email protected]>
Closes: api-platform#6906 Signed-off-by: Tobias Oitzinger <[email protected]>
Closes: api-platform#6906 Signed-off-by: Tobias Oitzinger <[email protected]>
Closes: api-platform#6906 Signed-off-by: Tobias Oitzinger <[email protected]>
Closes: api-platform#6906 Signed-off-by: Tobias Oitzinger <[email protected]>
API Platform version(s) affected: 4.0.12
Description
I have a model with a
status
property what I'm trying to cast to Enum:but in the response the
status
will be[]
:If I remove the casting from the model, the status display properly:
Additional Context
I traced the error back to
AbstractItemNormalizer
. It seems like something is going wrong here somewhere.ApiPlatform\Serializer\AbstractItemNormalizer::getAttributeValue()
The text was updated successfully, but these errors were encountered: