Laravel models manages the datetime attributes of a model converting them to a Carbon date instance. The model knows which fields have a date type using the $dates attribute of the model instance. The name is pretty descriptive, is a list that contains the name of each field in the model that will be converted to Carbon when is got. If the DB contains an invalid value not recognized by Carbon, we will encounter the error:
Provoked by an InvalidArgumentException thrown previously by Carbon.
In mi case, the problem was a DB record inserted manually, outside the app. This record had a date with a Carbon invalid format, but valid and correct for PostgreSQL:
The solution was simple, removing the milliseconds part because in my case it’s negligible.