vendredi 3 février 2017

Laravel: Change format of Carbon dates in models when converted to JSON

Currently, when I convert a model to JSON, all Carbon date fields are casted like so:

"end_time": {
    "date": "2017-02-03 23:59:00.000000",
    "timezone_type": 3,
    "timezone": "Europe/London"
}

I want it casted using the Atom notation. This can be done in carbon like so:

$order->end_time->toAtomString()

where $date is a Carbon date.

How can I make a model convert dates in the atom format when converting it to JSON?

I am aware that it is possible to append data like so: http://ift.tt/2kq3Q5e

But this does not change the format of an existing value?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire