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

[10.x] Add Enum Support to the In and NotIn Validation Rules #48247

Merged

Conversation

geisi
Copy link
Contributor

@geisi geisi commented Aug 30, 2023

Greetings Laravel Team,

This pull request introduces enhanced support for Enum types within the In and NotIn validation rules.

Motivation:

In many scenarios, developers might want to validate an input against a specific subset of enum values. Unfortunately, the current Laravel validation rules for In and NotIn do not natively support this functionality.

Changes Introduced:

With this PR, the validation against enum values can be seamlessly performed using the provided syntax:

enum Color: string
{
   case RED = 'red';
   case GREEN = 'green';
   case BLUE = 'blue';
}

Validator::validate(['color'=>'green'], ['color'=> [Rule::in([Color::RED, Color::GREEN])]]);

Looking forward to your feedback and hoping for a positive consideration.

@hafezdivandari
Copy link
Contributor

Although I think it's a better approach to make existing rules more functional and flexible than introducing new ones, but this is recently tried on #47630 and closed due to exsitance of new enum rule.

@geisi
Copy link
Contributor Author

geisi commented Aug 30, 2023

Thank you for pointing out the recent attempt in #47630. While there is indeed an existing Enum rule, enhancing the In rules offers functionality that the current Enum Rule doesn't provide. Please refer to my example for clarity.

@taylorotwell taylorotwell merged commit 4989e6d into laravel:10.x Aug 30, 2023
@geisi geisi deleted the add-enum-support-to-in-validation-rule branch August 30, 2023 19:09
@MarekVikartovsky
Copy link

at least this feature was approved :)

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.

4 participants