database
database copied to clipboard
Laravel + Postgresql timestamp with timezone
Using Postgres timestamp with time zone
column with Laravel causes an issue with Carbon
InvalidArgumentException in Carbon.php line 414:
Trailing data
This is because the data returned by Postgres include the +00
timezone information on the end. One fix would be to override getDateFormat
and have it return 'Y-m-d H:i:sO'
but of course we'd only want to do that where timezones are being used.
Models can override their own dateFormat
property, but pivot tables with timestamps can't do this (since there's no actual model for them).
:+1:
Are there any updates on this issue ? We're facing the same problem.
I had forgotten about this. You can actually create a subclass of the Pivot class and set the timestamp format there. Then in a subclass of Laravel Model class you can override the newPivot method to return an instant of your own Pivot.
It's a bit of a mess to get working, but it should do the job. We've actually moved away from using pivots at all and instead give the Pivot tables their own eloquent model class since it's just easier to work with them that way.
any update?
You just need to set your dateFormat
in the Model class accordingly:
protected $dateFormat = 'Y-m-d H:i:sO';
shows below error :The timezone could not be found in the database