Skip to content
Advertisement

Laravel IN Validation or Validation by ENUM Values

I’m initiating in Laravel. I searched and not found how to validate data with some ENUM values. On below code I need that type must be just DEFAULT or SOCIAL. One or other:

$validator = Validator::make(Input::only(['username', 'password', 'type']), [
    'type' => '', // DEFAULT or SOCIAL values
    'username' => 'required|min:6|max:255',
    'password' => 'required|min:6|max:255'
]);

Is possible?

Advertisement

Answer

in:DEFAULT,SOCIAL
The field under validation must be included in the given list of values.

not_in:DEFAULT,SOCIAL
The field under validation must not be included in the given list of values.

$validator = Validator::make(Input::only(['username', 'password', 'type']), [
    'type' => 'in:DEFAULT,SOCIAL', // DEFAULT or SOCIAL values
    'username' => 'required|min:6|max:255',
    'password' => 'required|min:6|max:255'
]);

🙂

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement