spatie / laravel-data

Powerful data objects for Laravel
https://spatie.be/docs/laravel-data/
MIT License
1.28k stars 209 forks source link

Passing an enum to caster handle without an error #841

Closed lkmadushan closed 3 weeks ago

lkmadushan commented 2 months ago

Allow to pass an enum to Structure::validateAndCreate method.

Previously below code didn't work.

Structure::validateAndCreate([
    'enum' => DummyBackedEnum::FOO
])

Some libraries (ex: Lighthouse PHP) which is a GraphQL implementation, sends Enum types through the request. I think we don't need to send the Enum string value again to the validate method. It should accept Enum types also.

clementbirkle commented 2 months ago

I have the same issue with attributes that are collections of enums.

I get an error like: Object of class App\Enums\MyEnum could not be converted to string.

I think/hope that this PR should fix it as well.

rubenvanassche commented 3 weeks ago

Thanks!