I know this question is a bit dated, but I stumbled upon it when trying to come up with the same solution, and wanted to share how I went about solving it.
My advice would be not to change the timezone that the messages are stored in. Store them in the database as UTC. Keeping your storage set to a constant frame of reference and then converting it to whatever timezone you need it displayed in will save you loads of headache over the long run.
As an example of one of those headaches, imagine two people trying to coordinate a meeting time in different timezones where one observes DST and one doesn't and you need to display the time in each user's local time. How hard would it be to convert your stored PDT time to say, the America/Cayman (which doesn't observe DST)? And how would you take in account when times are stored in PST vs PDT? How would you know? (Hint: without probably hundreds of lines of extra code just to answer that one question, you won't).
To get the time out in the correct timezone, simply add a mutator function on the model itself:
use Carbon\Carbon;
class MyModel extends Eloquent
{
public function getCreatedAtAttribute($value)
{
return Carbon::createFromTimestamp(strtotime($value))
->timezone('America/Los_Angeles')
->toDateTimeString()
;
}
}
Now, whenever you do $myModel->created_at
it will magically be converted into the correct timezone, but you still keep UTC in your database which definitely has its perks over other timezones for persistent storage.
Want to let users set their own timezones? Change the function to this:
public function getCreatedAtAttribute($value)
{
$user = Auth::user();
// If no user is logged in, we'll just default to the
// application's timezone
$timezone = $user ? $user->timezone : Config::get('app.timezone');
return Carbon::createFromTimestamp(strtotime($value))
->timezone($timezone)
// Leave this part off if you want to keep the property as
// a Carbon object rather than always just returning a string
->toDateTimeString()
;
}
And all of the complexity of changing timezones, taking daylight savings into account or not is abstracted away from you and you can forget that it even has to happen.
For more information about Laravel mutators / accessors, checkout the documentation.