I want to return json wit all the data with a timestamp datatype turned into ISO 8601 automatically. This should be easily achievable after Laravel 7 but I still face the issue.
I have created two columns start_time and end_time with the timestamp data type. While returning the results in JSON, Laravel only converts created_at and updated_at into ISO8601 (e.g. 2022-04-26T09:44:47.000000Z). The two columns I created are returned as they are stored in the database (e.g. 2022-01-17 19:45:07).
Anything I added in serializeDate() to replace the default method would only affect created_at and updated_at.
The closest I can get is to add below to my model, but it still has a slight difference in format (e.g. 2022-04-26T10:30:00Z vs 2022-04-26T09:44:47.000000Z).
protected $casts = [
'start_time' => 'date:Y-m-d\TH:i:s\Z',
'end_time' => 'date:Y-m-d\TH:i:s\Z',
];