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

jhutto's avatar

Livewire - Date Input - Getting db value

I have a edit form that I've setup with a date input.

	<td class="p-1 border border-gray-400 bg-white text-left text-lg text-black w-4/12">
              <input wire:model="begin_date" id="begin_date" name="begin_date"
                type="date" class="text-sm sm:text-base pl-2 pr-4 rounded-lg border border-gray-400 w-full py-2 	 
                               focus:outline-none focus:border-blue-400" />
              @error('begin_date')
               <div class="text-sm text-red-500 ml-1">
              @enderror  
    </td>

I'm pulling the information from database with no problem. Verified with dd($data)

Mounting the wire:model

$this->begin_date = $course->begin_date;

The input is providing information when submitted and date is picked. But just can't get it to display the date that is retrieved from database and sent to wire:model

Any ideas?????

0 likes
2 replies
Snapey's avatar
Snapey
Best Answer
Level 122

try initialising the value to a string in the format accepted by the date field

$this->begin_date = $course->begin_date->format('Y-m-d');

assuming that your begin_date is cast to Carbon.

3 likes
jhutto's avatar

It worked great... Thanks for your help. I learned something new... Did not know about castings.

Please or to participate in this conversation.