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

[8.x] Fail enum validation with pure enums #39926

Merged

Conversation

goodevilgenius
Copy link
Contributor

The current enum validation (#39437) throws an error if a pure enum is used. Since a pure enum doesn't make sense in this context, the validation should simply fail. This is similar to the behavior for if the validation is used on PHP < 8.1.

Consider the following code:

enum PureEnum
{
    case ONE;
    case TWO;
}

validator(
    ['status' => 'ONE'],
    ['status' => [new Enum(PureEnum::class)],
)->validate();

This code will throw an error, because the code expects a tryFrom static method on the enum. This method only exists on backed enums.

@taylorotwell taylorotwell merged commit f36fea7 into laravel:8.x Dec 7, 2021
@goodevilgenius goodevilgenius deleted the bug/pure-enums-fail-validation branch December 7, 2021 19:52
@marcoaureliocardoso
Copy link

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

Successfully merging this pull request may close these issues.

3 participants