You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
✏️ Describe the bug
In User model I have cast database column roles (which contains enum values in array format e.g. ["ADMIN","EMPLOYEE"]) to ArrayObject with Enums.
When trying to return it in DTO as array, I receive:
App\\DTO\\Response\\User\\UserDto::__construct(): Argument #8 ($roles) must be of type array, Illuminate\\Database\\Eloquent\\Casts\\ArrayObject given, called in /app/vendor/spatie/laravel-data/src/Resolvers/DataFromArrayResolver.php on line 95
It worked fine in version 4.6.0
Currently I did workaround:
After several hours of debugging, I traced the issue to this change. However, I couldn't find documentation supporting this usage. I make a PR to support if this functionality is desired.
This feels like valid behavior to me since you're using an ArrayObject cast within Eloquent which will return an ArrayObject, if you want this to work use an ArrayObject within your Data class. No idea why Laravel doesn't support casting into an array of enums but I don't think laravel-data should change types on the fly.
✏️ Describe the bug
In User model I have cast database column
roles
(which contains enum values in array format e.g.["ADMIN","EMPLOYEE"]
) to ArrayObject with Enums.When trying to return it in DTO as array, I receive:
It worked fine in version
4.6.0
Currently I did workaround:
↪️ To Reproduce
User Model:
UserDto Class:
Than:
UserDto::from($user)
✅ Expected behavior
Illuminate\Database\Eloquent\Casts\ArrayObject
should be casted to array, e.g.:🖥️ Versions
Laravel: 11.33.2
Laravel Data: 4.11.1
PHP: 8.3.14
The text was updated successfully, but these errors were encountered: