Example:
Validator::make(['x' => ''], ['x' => 'nullable|integer|min:1'])->errors()->all();
Output:
[]
When x
is null or 1,2,3, etc. it works fine.
When x
is something else except empty string validator says about errors.
Column in database can be NULL or positive integer so when I pass empty string, validator tells me that it's fine, but mysql throws exception because it tries to save ''
(empty string) in nullable integer column.
Only allowed values for field are: null
, 1,2,3,4,...
, everything else should fail.
If I add required
rule then validator fails for null
value ('nullable|required|integer|min:1')
nullable
only says, that value can benull
, but it does not convert empty value tonull
itself. – Autista_znullable
is not really in effect here. If you doValidator::make(['x' => ''], ['x' => 'integer|min:1'])->errors()->all();
you still get no errors – apokryfos