Accessing a model property stops error message appearing - why? #824
-
Hi all, I'm struggling to get a laravel-data Data object to instantiate from an eloquent Model and I can't figure out why. The strange thing, is that accessing the property (e.g. via a var_dump) causes the error message to disappear. Here's the code in question:
And the error: _app\Data\CarData::_construct(): Argument #2 ($type) must be of type app\Enums\CarType, string given, called in /var/www/vendor/spatie/laravel-data/src/Resolvers/DataFromArrayResolver.php on line... I've posted a more extensive summary on StackOverflow here, but I think the crux of the issue is that the Enum is not being converted before the Data object receives the array, despite the cast being correct. However, when we access that property, the cast is evaluated and stored for future use. This appears very strange to me. It's entirely possible I've missed something vital as I'm fairly new to to this - perhaps some local/dev environment setup specific thing, but I don't think I've done anything unusual and I've tried to follow the docs precisely. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Many hours later and I've figured out the problem as simple the capitalisation of one of my use statements in the Data class - that's a rookie error on my part, but I wondered if perhaps the error message should be more helpful (e.g. cannot find enum CarType)? |
Beta Was this translation helpful? Give feedback.
Many hours later and I've figured out the problem as simple the capitalisation of one of my use statements in the Data class - that's a rookie error on my part, but I wondered if perhaps the error message should be more helpful (e.g. cannot find enum CarType)?