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

jbowman99's avatar

Eager Load Carbon date into an Edit form

I am using Jquery UI datepicker to select a date for a field in a create form. When the form is to be edited the Dates are not populating with the input data?

trying to eager load but not succeeding. Can i eager load a Carbon instance into an edit form?

0 likes
5 replies
Snapey's avatar

Yes sure, but you might need to apply some formatting.

Show some code? Are you using the Form helpers? Form model binding? Is the date flagged as a datetime field in your model - by default only updated_at and created_at get converted to Carbon instances.

jbowman99's avatar

@Snapey

here is what i was trying to do with the form:

 <div class="form-group">
                {!! Form::label('date_of_death', 'Date of death:') !!}
                {!! Form::input('date', 'date_of_death', \Carbon\Carbon::parse($obit->date_of_death['date'])->diffForHumans(), ['class' => 'form-control datepick2', 'placeholder' => 'click to enter', 'readonly' => true]) !!}
            </div>

here is the dump of the date i'm trying to grab:

Carbon {#293 ▼
  +"date": "2015-09-23 00:00:00.000000"
  +"timezone_type": 3
  +"timezone": "America/Chicago"
}

Snapey's avatar

Well if date_of_death is a Carbon instance, you should not need to parse it. just date->diffForHumans()

Try it outside of the form and see what you get?

Also, review the source being passed to the browser. What source do you get for the input field?

jbowman99's avatar

@Snapey source for that field. when i just try and eager load it like $obit->date_of_death

<div class="form-group">
                <label for="date_of_death">Date of death:</label>
                <input class="form-control datepick2" placeholder="click to enter" readonly="1" name="date_of_death" type="date"             value="2015-09-23 00:00:00" id="date_of_death">
            </div>

Snapey's avatar

so you are getting a date passed through...

not sure what diffForHumans is for though?

Please or to participate in this conversation.