validation icon indicating copy to clipboard operation
validation copied to clipboard

Before & After: Should not throw an exception if the value is empty.

Open mahyarkhanbabai opened this issue 3 years ago • 1 comments

Hey, I have a validator rule like this:

$validator->make($_POST, 'dateOfBirth'=>'date:Y/m/d|before:today' );

As you can see, the date field is not required, it is optional, but if someone wants to enter it, it must be in the given format and before today. The problem is when the user leaves the field empty, we get an error that says: ... Argument #1 ($date) must be of type string, null given, called in ...

So you get the point. I am pretty sure we should leave checking the value for empty/null values for the "required" rule and return true if the field is empty, in "before and after" rules.

mahyarkhanbabai avatar Aug 05 '22 07:08 mahyarkhanbabai

I think the logic is correct. You doesn't require the field but you don't say it is optional. Use "nullable" if it is not required. Then the validation bails is the field is empty.

xJuvi avatar Apr 07 '24 15:04 xJuvi