Needs a 'nullable' rule
shrimpwagon opened this issue · 1 comments
shrimpwagon commented
This is very useful especially for dates. Where it is optional and can be null but can also be a valid date.
Look up Laravel's validation rules. They have it too and it explains more.
willemwollebrants commented
We have it, but it's called 'optional':
From the readme
optional - Value does not need to be included in data array. If it is however, it must pass validation.
$validator = new \Valitron\Validator();
$validator->rule('optional', 'date');
$validator->rule('date', 'some_date');
//field not set
$validator->validate(); //true
//field is null
$validator->withData(['some_date'=>null])->validate(); //true
//value is valid
$validator->withData(['some_date'=>'2020-02-21'])->validate(); //true
//value is not valid
$validator->withData(['some_date'=>'not a date'])->validate(); //false