Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SdeWijs's avatar

ISO8601 date serialization in Laravel 7

I noticed that Laravel does not cast all timestamp columns to the ISO8601 format out-of-the-box. If I return a model (in response to an Ajax request), which is converted to JSON by default, the created_at and updated_at are in ISO format, but another timestamp column that I added via a migration is kept in the MYSQL Y-m-d H:i:s format.

Reading the docs, it seemed to me that unless you override the serializeDate() method of the model, all timestamps will be converted to ISO8601 in Laravel 7. Is this a correct assumption or do I need to use the serializeDate() method to convert columns other than the default timestamps columns?

Update

If I explicitly call $model->toJson() The custom timestamp column is converted to ISO8601 format.

Update 2

Just upgraded to Laravel 7.3.0 and it seems they fixed this behaviour. Now all timestamp columns are converted to ISO8601 format out-of-the-box

0 likes
0 replies

Please or to participate in this conversation.