I remember well when I used Laravel 4 that it was possible to globally convert the formats of created_at
and updated_at
, to display in JSON responses or even to the {{ $model->created_at }}
direct call.
I did the following:
# app/global.php
Carbon\Carbon::setToStringFormat('d/m/Y H:i');
So, every time I called the Response::json
or Model::toJson()
method, the dates were converted to the above format.
But now this has not happened. Generally, I use a method called getCreatedAtBrAttribute
to get the dates with the formatting. I also went so far as to use MomentJs
to convert those dates through Javascript.
But now I want a solution in Laravel itself.
Is there a way in Laravel 5 to make all dates have a default format when they are called as a string?