My validator rule looks like this:
$validator = Validator::make($request->all(), [
'name' => 'required|min:5|max:255',
'email' => [
'required',
'max:255',
'email',
Rule::unique('users')->ignore($id),
],
'password' => 'min:6|confirmed',
], [
'confirmed' => 'Hasło musi się zgadzać',
'unique' => 'Wpisz inny adres email, ten adres jest zajęty',
'required' => 'To pole jest wymagane.',
'min' => 'To pole musi mieć minimum :min znaków.',
]);
if ($validator->fails()) {
return redirect('/panel/users/'.$id.'/edit')
->withErrors($validator)
->withInput();
}
When i edit user without change password, validator fails with 'min' rule. As you can see my validator doesnt require password, so why it validating?
use nullable rule
'nullable|min:6|confirmed'
It's look like what you want.
$validator->sometimes('password', 'min:6|confirmed', function ($input) {
return (strlen($input->password) > 0);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With