I'm not sure where this comes from but the default HTML
datepicker is off by one day while using laravel
and livewire
.
This code:
<div class="col-span-6 sm:col-span-4">
<x-jet-label for="birthdate" value="{{ __('Geburtsdatum') }}" />
<x-jet-input id="birthdate" name="birthdate" type="date" class="mt-1 mb-6 w-full" wire:model="details.birthdate"/>
<x-jet-input-error for="details.birthdate" class="mt-2" />
{{$details->birthdate}}
</div>
ends up like this:
I use this code to ensure that the birthday format in my model is the way that I expect it to be:
protected $casts = [
'birthdate' => 'date:Y-m-d',
];
The same with the validation rules in my livewire component:
protected $rules = [
'details.birthdate' => 'date:Y-m-d',
];
Also i use the date
format in my mysql
database.
And the value seems to be right as 2021-02-02
but inserting this using wire:model
it ends up as 2021-02-01
.
Does someone know where this behaviour comes from?
Finally we found what was causing the problem. We had a protected variable in our model
:
protected $dates = ['birthdate'];
After deleting this, if finally worked. Thanks for your help.