Laravel Password & Password_Confirmation Validation

I used this to edit user account information:

$this->validate($request, [ 'password' => 'min:6', 'password_confirmation' => 'required_with:password|same:password|min:6' ]); 

This worked fine in Laravel 5.2 application, but not in 5.4 application.

image

What is wrong or how to do it correctly to make password mandatory only if the password or password_confirmation field is set?

+33
source share
5 answers

You can use the confirmed validation rule.

 $this->validate($request, [ 'name' => 'required|min:3|max:50', 'email' => 'email', 'vat_number' => 'max:13', 'password' => 'required|confirmed|min:6', ]); 
+66
source

Try to do it like this, I succeeded:

 $this->validate($request, [ 'name' => 'required|min:3|max:50', 'email' => 'email', 'vat_number' => 'max:13', 'password' => 'min:6|required_with:password_confirmation|same:password_confirmation', 'password_confirmation' => 'min:6' ]);' 

It seems that the rule always has a first-entry check among the pair ...

+28
source

try to confirm without the password_confirmation rule:

 $this->validate($request, [ 'name' => 'required|min:3|max:50', 'email' => 'email', 'vat_number' => 'max:13', 'password' => 'confirmed|min:6', ]); 
+7
source

Try the following:

 'password' => 'required|min:6|confirmed', 'password_confirmation' => 'required|min:6' 
+3
source

This should be enough to do:

 $this->validate($request, [ 'password' => 'nullable,min:6,confirmed', ]); 

Make the password optional, but if it does, a password confirmation is required that matches

0
source

Source: https://habr.com/ru/post/1265088/


All Articles