dimanche 18 août 2019

Laravel 5.8, validation fails on applying a custom rule

This works perfectly fine. When passing a null value, the nullable tag does its job of ignoring the validation if email is null.

 Validator::make($request->all(), [
   'email' => 'nullable|unique:users,email|email|max:50',
 ])->validate();

Below code fails when a null value is passed. The nullable tag does not seem to work and the validation directly jumps to the email tag and fails the validation with error

The email must be a valid email address.

Validator::make($request->all(), [
    'email' => [
            'nullable',
            'email',
            'max:50',
            Rule::unique('users', 'email')->ignore($request->userId),
        ],
 ])->validate();



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/31N5tP6
via IFTTT

Aucun commentaire:

Enregistrer un commentaire