F
Filament6mo ago
Stevee

TextInput integer save 0 as null

here is my code
TextInput::make('amount')
->integer()
->minValue(0)
->required()
TextInput::make('amount')
->integer()
->minValue(0)
->required()
if user put 0 into it, it saved as null instead of '0'
Solution:
```php public function getAmountAttribute($value) { return $value ?? 0; }...
Jump to solution
5 Replies
YusifHajiyev
YusifHajiyev6mo ago
->default(null)
Stevee
Stevee6mo ago
still save as null
toeknee
toeknee6mo ago
Set a default cast if you want it to save as 0 using an accessor?
Solution
toeknee
toeknee6mo ago
public function getAmountAttribute($value)
{
return $value ?? 0;
}
public function getAmountAttribute($value)
{
return $value ?? 0;
}
On your model.
Stevee
Stevee6mo ago
thank youu