I’m using Laravel Livewire’s #[Validate]
on a nullable field, and I only want to validate the field as an integer.
...
#[Validate('integer', message: 'Asking price must be an integer.')]
public $business_asking_price;
...
The code above works to ensure the user enters only integers but doesn’t allow the field to remain null.
2
Answers
When saving the field with no value previously added, I didn't get the error, it was only when I deleted the value and tried to save the form is when I saw the error. When deleting the current value,
""
was saved in its place and it errored out. All I did to fix it was make sure Null was added to the field with'business_asking_price' => $this->business_asking_price ?? Null,
.Try
nullable
: