Laravel - Display DateTime Value in Edit Form

2019-08-25 07:19发布

How can I display my data which is a DateTime value in my edit form?

input="datetime-local."

Here's what my DateTime value looks like: 2018-04-02 04:04:00.

I want it to display in this input:

<input type="datetime-local" name="flight_date" class="form-control">

my $variable->data

$aircraftFlight->flight_date

EDIT VAR DUMP

object(App\AircraftFlights)#527 (26) { ["table":protected]=> string(16) "aircraft_flights" ["primaryKey"]=> string(2) "id" ["timestamps"]=> bool(false) ["connection":protected]=> string(5) "mysql" ["keyType":protected]=> string(3) "int" ["incrementing"]=> bool(true) ["with":protected]=> array(0) { } ["withCount":protected]=> array(0) { } ["perPage":protected]=> int(15) ["exists"]=> bool(true) ["wasRecentlyCreated"]=> bool(false) ["attributes":protected]=> array(9) { ["id"]=> int(1) ["flight_number"]=> string(10) "AA-0000003" ["iata_flight_number"]=> string(5) "ABCD2" ["flight_date"]=> string(19) "2018-04-02 04:04:00" ["departure_time"]=> string(19) "2018-05-04 01:59:00" ["arrival_time"]=> string(19) "2018-05-05 13:59:00" ["from_location"]=> string(11) "Afghanistan" ["destination"]=> string(7) "Albania" ["aircraft_id"]=> int(1) } ["original":protected]=> array(9) { ["id"]=> int(1) ["flight_number"]=> string(10) "AA-0000003" ["iata_flight_number"]=> string(5) "ABCD2" ["flight_date"]=> string(19) "2018-04-02 04:04:00" ["departure_time"]=> string(19) "2018-05-04 01:59:00" ["arrival_time"]=> string(19) "2018-05-05 13:59:00" ["from_location"]=> string(11) "Afghanistan" ["destination"]=> string(7) "Albania" ["aircraft_id"]=> int(1) } ["changes":protected]=> array(0) { } ["casts":protected]=> array(0) { } ["dates":protected]=> array(0) { } ["dateFormat":protected]=> NULL ["appends":protected]=> array(0) { } ["dispatchesEvents":protected]=> array(0) { } ["observables":protected]=> array(0) { } ["relations":protected]=> array(0) { } ["touches":protected]=> array(0) { } ["hidden":protected]=> array(0) { } ["visible":protected]=> array(0) { } ["fillable":protected]=> array(0) { } ["guarded":protected]=> array(1) { [0]=> string(1) "*" } }

3条回答
霸刀☆藐视天下
2楼-- · 2019-08-25 07:57

Put your variable on input type text value

<input type="text" name="flight_date" class="form-control" value="{{ $aircraftFlight->flight_date }}">

You can use php date() function to format your variable here is the link: http://php.net/manual/en/function.date.php

format into this

date('Y-m-d h:i:s', strtotime($aircraftFlight->flight_date))
查看更多
Bombasti
3楼-- · 2019-08-25 07:59

I would use a date time picker with the input type as text and set the id to flight_date

have a look at this one:

https://eonasdan.github.io/bootstrap-datetimepicker/

There are a number around this is just the first I came across

Hope this helps

Update

This is the one that we use at work and I know it works

https://www.eyecon.ro/bootstrap-datepicker/

Try that.

查看更多
可以哭但决不认输i
4楼-- · 2019-08-25 08:09

try using carbon to format date:

<input type="datetime-local" name="flight_date" class="form-control" value="{{ \Carbon\Carbon::parse($aircraftFlight->flight_date)->format('yyyy-MM-ddThh:mm')}}">

Note: type="datetime-local" is not supported in Firefox, Safari or Internet Explorer 12 (or earlier).

查看更多
登录 后发表回答