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

info@tithink.com's avatar

Laravel validation 'different' fails when other attribute is null

Hello I'm having troubles with the different validation.

I have 2 variables that can be null. What I want to achieve is whenever the variable is present, force it to have exactly 5 digits and not to have the same value.

These are the rules that I've set:

'zip_departure' => 'nullable|digits:5',
'zip_arrival' => 'nullable|different:zip_departure|digits:5',

The problem is when I set zip_departure as null it throws up a validation error saying both parameters cannot have the same value. But if I dd() both variables they have:

'zip_departure': null
'zip_arrival': '28100'

What am I missing here?

I'm using Laravel 5.6

0 likes
0 replies

Please or to participate in this conversation.