I have a form with a modal and one of the fields in the form is a date field. It is cast in the Model as:
'date_last_contact' => 'date:m/d/Y',
In the $rules section of the livewire file it is set as:
'editing.date_last_contact' => 'date|nullable',
The issue is if I put a non-date non-null value in field and try to save it throws an error because it is not validating…
Carbon\Exceptions\InvalidFormatException
Could not parse ‘adff’: DateTime::__construct(): Failed to parse time string (adff) at position 0 (a): The timezone could not be found in the database
The Save function in the livewire file looks like this:
public function save()
{
$this->validate();
$this->editing->save();
$this->showEditModal = false;
}
What it seems is happening it is trying to CAST it to a date before the validation is happening. How can this be prevented?
Laravel Version: 8.24.0
Livewire Version: 2.3.8