I know this question is a bit outdated, but I came across it, trying to find the same solution, and wanted to share how I decided to solve it.
My advice is not to change the time zone in which the messages are stored. Store them in a database in UTC format. Keeping your vault in a constant reference system, and then converting it to any time zone you need, displays it for a long time.
As an example of one of these headaches, imagine that two people are trying to coordinate meeting times in different time zones where DST is observed, and one is not, and you need to display the time in each user local time. How difficult would it be to convert your stored PDT time to say: America / Cayman (which does not comply with DST)? And how will you consider when time is stored in PST and PDT? How do you know? (Hint: without probably hundreds of lines of additional code, you wonβt be able to answer one question).
To get a timeout in the correct time zone, simply add the mutator function to the model itself:
use Carbon\Carbon; class MyModel extends Eloquent {
Now when you do $myModel->created_at , it magically converts to the correct time zone, but you still save the UTC in your database, which definitely has advantages over other time zones for permanent storage.
Want users to set their own time zones? Change the function as follows:
public function getCreatedAtAttribute($value) { $user = Auth::user();
And the whole complexity of changing time zones, taking into account savings or not, is distracted from you, and you can forget that this should even happen.
For more information on Laravel mutators / accessories, check out the documentation .
Jeff lambert
source share