Skip to content
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

Eloquent enum casting: toArray throws exception when overriding getEnumCastableAttributeValue #42658

Closed
henzeb opened this issue Jun 3, 2022 · 5 comments

Comments

@henzeb
Copy link
Contributor

henzeb commented Jun 3, 2022

  • Laravel Version: 9.16.0
  • PHP Version: 8.1.6
  • Database Driver & Version: -

Description:

I have been trying to get basic enumerations to work for a package of mine, but I keep hitting walls (also see #42648)
When trying to use getEnumCastableAttributeValue / setEnumCastableAttribute this works perfectly, but when using toArray after setting a basic enum value, UnitEnum instance that is, it is casting it back in to an enum and is trying to use it's value property, on line 301 in HasAttributes.

Steps To Reproduce:

just clone and install https://github.com/henzeb/laravelCastbug

then run ./artisan test:bug

You can find the code in the standard User.php model, \App\MyUnitEnum enum and in \App\Console\Commands\testBugCommand.

@rodrigopedra
Copy link
Contributor

@henzeb I sent a new comment to the discussion #42648 that might help you out with your package

Check it out: #42648 (comment)

@driesvints
Copy link
Member

Seems this is a Symfony issue. Please don't upgrade to Symfony v6.1 for now and wait until they release a patch release.

@henzeb
Copy link
Contributor Author

henzeb commented Jun 7, 2022

how exactly is this a Symfony issue? the error happens in \Illuminate\Database\Eloquent\Concerns\HasAttributes, nowhere near symfony....

@driesvints
Copy link
Member

ah sorry, we received tons of issues about a symfony breakage and thought this one was one as well. There's no bug here though. The behavior you mentioned isn't supported. Please see Rodrigo's comment.

@henzeb
Copy link
Contributor Author

henzeb commented Jun 7, 2022

Alrighty then. Workaround with checking where the method is called and return anonymous class with value when needed it is then....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants