Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Chris1989's avatar

html default date picker and livewire

I have problem with default datepicker using livewire, doesn't keep the value from model, when edit a form that has date doesnt see on date picker .

0 likes
6 replies
Chris1989's avatar

I have that on my laravel livewire form:

   <input type="date" wire:model.debounce.300ms="start_date"
                                class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md"
                                value="{{ Carbon\Carbon::parse($start_date)->format('Y-m-d') }}">

 </div>

Look the gif that is very detailed, simply when i remove the wire:model that is necessary, it saws the date...

https://ibb.co/7y66fbT

mvd's avatar

H @chris1989

it is because $start_date is not in the Y-m-d format.

You can cast $start_date in your model

Example:

class YourModel extends Model
{
    protected $casts = [
        'start_date' => 'date:Y-m-d'
    ];
}
3 likes
Chris1989's avatar

No doesnt work, unfortunately i tried, i have already that in my model, i think is something with livewire or bug.

mvd's avatar
mvd
Best Answer
Level 48

@chris1989

I can reproduce this, I don't think it is a Livewire bug.

In my Livewire component

function render() {
	$this->start_date = Carbon::now();
	return view('.....
}

De date field is empty (just showing placeholder 'dd-mm-jjjj')

If a do

function render() {
	$this->start_date = Carbon::now()->format('Y-m-d');
	return view('....
}

It is showing the date (01-07-2021)

2 likes

Please or to participate in this conversation.