Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Bartude's avatar

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)

0 likes
2 replies
Bartude's avatar

@Vilfago bail only stops running validation rules on an attribute it's on. Even if required fails, it will still pass onto the new_password rules

Please or to participate in this conversation.