You can maybe try to use bail on old_password
Validation different rule triggering when field is null
Laravel Version: 5.5 PHP: 7.2.9
I'm trying to reset a user password and first I want to do some validation, like this:
$this->validate($request, [
'old_password' => 'required',
'new_password' => 'required|different:old_password|confirmed',
]);
However, in my form, if I don't fill the old_password, but fill in the other two fields new_password and new_password_confirmation, I'm getting both an error of The old password field is required. and also The new password and old password must be different..
I checked the request object and old_password is being passed as null, and new_password has a string, so they should be different and the rule shouldn't be triggering.
Is this the expected behavior? If so, how can I make it so this error doesn't show up, or make it so only the first error shows in case it fails? (I could create two validations like above, one for each attribute, but that seems like a shortcut, which I would like to avoid)
Please or to participate in this conversation.