InvalidArgumentException with message 'Trailing data' for a date field

Published 1 year ago by polarcubs

Hi for some reason when I try to access an existing database table created_at field I keep getting a InvalidArgumentException with message 'Trailing data' error.

The value of created_at is something like this:

2015-03-12 09:25:42.383103

How do I fix it?

In my models I had $dates array defined. in $casts I defined created_at as a datetime field. I commented both out but I still get the same error. It's a postgres database. I don't have the rights to modify the database table only the code.

I searched Github and it appear a few people has filed this issue with Postgres & laravel, however @TaylorOtwell closed each of them. Does anybody know of a fix I can apply?

1 year ago (179,600 XP)

If you can't modify your database, you can add this to your model:

    protected function getDateFormat()
        return 'Y-m-d H:i:s.u';

But, since this will affect all your models, I think it would be best to create a base model with this method and then have all your models extend this base class instead.

Please sign in or create an account to participate in this conversation.