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' ]);
🙂