Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mahyarkhanbabai opened this issue Aug 5, 2022 · 1 comment

Comments

@mahyarkhanbabai
Copy link

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.

@xJuvi
Copy link

xJuvi commented Apr 7, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants