0
votes

I'm using a Form Request to validate the update of a Client.

The following line keeps giving me the min:6 error, although there is 'sometimes' before it.

This is an update form, so the user password and password confirm field will be empty, for the update.

'users.password' => 'sometimes|confirmed|min:6',

So when I don't enter anything in the password (or password_confirm) field I still get the min: error

The Password must be at least 6 characters.

2
Use "nullable" instead of "sometimes" in rules : laravel.com/docs/5.5/validation#a-note-on-optional-fieldsDessauges Antoine
Use 'users.password' => 'sometimes|confirmed|min:6|nullable',Hiren Gohel
Thanks guys! That's indeed the answer.Miguel Stevens
@Notflip I have posted my answer! Don't forgot to upvote & accept the best answer! :)Hiren Gohel

2 Answers

3
votes

You can use

'users.password' => 'confirmed|min:6|nullable',

instead of

'users.password' => 'sometimes|confirmed|min:6',

Hope this helps you!!

1
votes

laravel validation "sometimes" will check for rules if the key exists in the request

so "sometimes" will pass the rules if the key is not found in the request

I think your request have "password" => null.

try to remove the key from the request so it will pass it.

check this image:

enter image description here