In the API portions of my Laravel apps, I'm used to datetime properties (such as created_at and updated_at) being formatted something like this:
"created_at": {
"date": "2018-12-04 00:44:39.000000",
"timezone_type": 3,
"timezone": "UTC"
},
However, in a new app I just recently made which uses Laravel 5.8, the datetime properties are being parsed something like this:
"created_at": "2018-11-19T16:37:07.000000Z",
I looked all over and can't find a reason for this discrepancy. I'm guessing it might be something changed in Laravel 5.8? Can somebody please explain to me how/why this happens? I'd like to change all of my datetime properties to use the latter more condensed format so that my API responses can be less bytes.
Also, in both cases I'm using Eloquent Resources and just simply returning a datetimes like:
public function toArray($request)
{
return [
'created_at' => $this->created_at,
];
}
This is consistent throughout, so I don't see why/where the discrepancy is. I also have $casts = ['created_at' => 'datetime'] in the models of both apps, so it is consistent there too. I don't see/understand why/how the datetimes are being formatted differently in the 2 different Laravel apps. If someone can help explain how/where this happens, it would be helpful and appreciated.
Thanks.