Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel + Postgresql timestamp with timezone #15

Open
EspadaV8 opened this issue Jul 17, 2015 · 6 comments
Open

Laravel + Postgresql timestamp with timezone #15

EspadaV8 opened this issue Jul 17, 2015 · 6 comments

Comments

@EspadaV8
Copy link
Contributor

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).

@matejvelikonja
Copy link

👍

@PatrickHoopman
Copy link

Are there any updates on this issue ? We're facing the same problem.

@EspadaV8
Copy link
Contributor Author

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.

@parabol
Copy link

parabol commented Nov 24, 2016

any update?

@mirzap
Copy link
Member

mirzap commented Apr 13, 2017

You just need to set your dateFormat in the Model class accordingly:

protected $dateFormat = 'Y-m-d H:i:sO';

@nareshsolulab
Copy link

shows below error :The timezone could not be found in the database

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants