1

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.

4
  • 1
    Use "nullable" instead of "sometimes" in rules : laravel.com/docs/5.5/validation#a-note-on-optional-fields Commented Oct 16, 2017 at 9:52
  • 1
    Use 'users.password' => 'sometimes|confirmed|min:6|nullable', Commented Oct 16, 2017 at 9:55
  • Thanks guys! That's indeed the answer. Commented Oct 16, 2017 at 9:58
  • 1
    @Notflip I have posted my answer! Don't forgot to upvote & accept the best answer! :) Commented Oct 16, 2017 at 10:59

2 Answers 2

3

You can use

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

instead of

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

Hope this helps you!!

Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

There has no required thing in his case, it's an optionnal field

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.