I have a "time" field in Db which is storing just time in format HH:MM:SS. User table contains field "timezone" which stores string like 'Asia/Kolkata' and few others. In model I have:
public function getTimeAttribute ($time){
return Carbon::parse($time)->setTimezone(Auth::user()->timezone)->format('H:i');}
which displayes what I need, so time stored in UTC + time difference resulting from timezone field.
What I do not know how to do is the other way round, so how to store this time from input in local timezone to UTC. So on the form I specify 18:00 and it stores it as 18:00:00 not taking timezone into account.
You can define a mutator which to convert the time to UTC - the second argument to parse sets the original timezone:
public function setTimeAttribute($value)
{
$this->attributes['time'] = Carbon::parse($value, Auth::user()->timezone)
->setTimezone('UTC)->format('H:i');
}