F
Filament12mo 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
YusifHajiyev12mo ago
->default(null)
Stevee
SteveeOP12mo ago
still save as null
toeknee
toeknee12mo ago
Set a default cast if you want it to save as 0 using an accessor?
Solution
toeknee
toeknee12mo ago
public function getAmountAttribute($value)
{
return $value ?? 0;
}
public function getAmountAttribute($value)
{
return $value ?? 0;
}
On your model.
Stevee
SteveeOP12mo ago
thank youu
Want results from more Discord servers?
Add your server