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

[9.x] Allow instance of Enum pass Enum Rule #42906

Merged
merged 2 commits into from
Jun 22, 2022
Merged

[9.x] Allow instance of Enum pass Enum Rule #42906

merged 2 commits into from
Jun 22, 2022

Conversation

cbaconnier
Copy link
Contributor

Given this scenario, the validation for country currently fail as it expect the value of CountryEnum.
Laravel will automatically cast the enum instance when saving the model, therefore, it should be safe to validate by it's instance.

$action = new CreateNewUser();

$action->create([
    'country' => CountryEnum::CH,
    'email'   => 'john.doe@example.org',
]);
public function create(array $input)
{
    Validator::make($input, [
        'country' => ['required',  Enum(CountryEnum::class)],
        'email'   => [...],
    ])->validate();
}

@taylorotwell taylorotwell merged commit f87031b into laravel:9.x Jun 22, 2022
@cbaconnier cbaconnier deleted the validate-enum-instance branch June 22, 2022 18:51
turanjanin pushed a commit to turanjanin/laravel-framework that referenced this pull request Jun 23, 2022
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.

2 participants