ImportField nullable but numeric when not empty

Hello, I'm looking for a way to make an ImportField nullable but when it is not null it should be numeric. I have tried this:
ImportColumn::make('minimum_stock')
->label('Minimale voorraad')
->ignoreBlankState(true)
->example(5)
->rules(['numeric']),
ImportColumn::make('minimum_stock')
->label('Minimale voorraad')
->ignoreBlankState(true)
->example(5)
->rules(['numeric']),
But when it is empty it says that it must be numeric. Any suggestions? Thanks.
Solution:
Add ‘ nullable’ to your rules array before ‘numeric’
Jump to solution
4 Replies
Solution
awcodes
awcodes15mo ago
Add ‘ nullable’ to your rules array before ‘numeric’
JJSanders
JJSandersOP15mo ago
It doesn't work when adding nullable before numeric
awcodes
awcodes15mo ago
not sure then, it's just standard Laravel validation rules though
JJSanders
JJSandersOP15mo ago
The mistake was in my database. The rules work

Did you find this page helpful?