Laravel Password & Password_Confirmation Validation

Scarwolf picture Scarwolf · Mar 6, 2017 · Viewed 143.1k times · Source

I've been using this in order to edit the User Account Info:

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

This worked fine in a Laravel 5.2 Application but does not work in a 5.4 Application.

image

What's wrong here, or what is the correct way in order to only make the password required if either the password or password_confirmation field is set?

Answer

Neabfi picture Neabfi · Mar 6, 2017

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