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

acedude's avatar

Collection::jsonSerialize() fails on Carbon date made from Postgresql timestamp

In short, using json_encode (Response::json()) on any model that contains timestamps when using Postgre returns a "Failed calling Illuminate\Database\Eloquent\Collection::jsonSerialize()" error.

In other words, dates like "2014-10-15 20:19:21.683" just kill Carbon.

The temporary solution is disabling date mutators by returning an empty array in getDates().

Did any of you ever experienced this?

0 likes
2 replies
masterpowers's avatar

This will Only Happen if Your Calling a row in the database with a timestamp that is set 0000-00-00 00:00:00 if you try to use a proper timestamp while protected $dates = ['created_at', 'updated_at']; is set you wont get any eror. Hope this info helps , you dont need to disable your protected $dates :)

Please or to participate in this conversation.