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
awcodes12mo ago
Add ‘ nullable’ to your rules array before ‘numeric’
JJSanders
JJSandersOP12mo ago
It doesn't work when adding nullable before numeric
awcodes
awcodes12mo ago
not sure then, it's just standard Laravel validation rules though
JJSanders
JJSandersOP12mo ago
The mistake was in my database. The rules work
Want results from more Discord servers?
Add your server