@naykel not sure I understand you correctly... Laravel offers https://laravel.com/docs/8.x/validation#rule-date and https://laravel.com/docs/8.x/validation#rule-date-format to validate input dates. Did you try that?
Livewire date casting and validation problem
I am trying to implement date validation on a livewire component, and it appears that date casting happens before validation resulting with errors.
After days of googling, I have tried so many things I am at a loss, but from what I have figured out this is only a problem when using nested properties.The common pattern I have found is:
In the model
protected $casts = [
'expires_at' => 'date',
];
protected $appends = ['expiry_date_for_editing'];
public function getExpiryDateForEditingAttribute()
{
return $this->expires_at->format('d/m/y');
}
public function setExpiryDateForEditingAttribute($value)
{
dd('why is firing before validation takes place?????');
$this->expires_at = Carbon::createFromFormat('d/m/y', $value)->format('Y-m-d');
}
In the livewire component validation rules I have
protected $rules = [
'editing.expiry_date_for_editing' => 'required',
];
I am aware that there is no date formatting in the validation rules above but I can't even get the required rule to fire. To test I deleted the date and tried to save save it just throws and error saying data missing.
Please or to participate in this conversation.