It looks like the issue is that the Pikaday date picker is not directly integrated with Livewire's data binding. When you select a date using Pikaday, it updates the input field, but it doesn't notify Livewire of the change. To fix this, you need to manually emit an event to Livewire when the date is selected.
Here's how you can modify your component to emit a Livewire event when the date changes:
<div x-data x-init="
new Pikaday({
field: $refs.input,
format: 'YYYY-MM-DD',
onSelect: function() {
$dispatch('input', this.getMoment().format('YYYY-MM-DD'))
}
})
" class="w-full">
<!-- ... rest of your component -->
<input x-ref="input" type="text"
wire:model.lazy="{{ $model }}"
{{ $attributes->merge([
'class' => 'pl-10 shadow-sm focus:ring-secondary focus:border-secondary block w-full sm:text-sm border-gray-300 rounded-md',
'type' => 'text',
]) }}
placeholder="DD-MM-YYYY">
<!-- ... rest of your component -->
</div>
In the x-init attribute, I've added an onSelect callback to the Pikaday configuration. This callback uses $dispatch to emit an input event with the selected date whenever a new date is picked. The wire:model.lazy directive is used to update the Livewire model only after the input event is dispatched, which should be when the user selects a date.
Make sure that your Livewire component is listening for the input event on the input element. If it's not, you can add an event listener like this:
protected $listeners = ['input' => 'updateDate'];
public function updateDate($value)
{
$this->start_date = $value;
$this->updated();
}
This will call the updateDate method on your Livewire component whenever the input event is dispatched, passing the selected date as $value. The updateDate method then updates the start_date property and calls the updated method to refresh the component with the new date.
Remember to test this solution and adjust it as necessary for your specific setup.