So I already save any date on my database with UTC, and I can get it just like $data->created_at or $data->blocked_at. So in my config, I set timezone to UTC, then i want to convert when on view from UTC to UTC+7 or another timezone.
Is there an easy way to convert timezone i want when on view for all dates?
I'm still using Laravel 5.8
Edit:
I'm using the answer but implement that on my base model, like this:
public function getDateConverter($key){
if(strtotime($this->{$key})){
$date = Carbon::createFromFormat('Y-m-d H:i:s', $this->{$key});
$date->setTimezone(env("APP_TIMEZONE_VIEW"));
return $date->toDateTimeString();
} else {
return null;
}
}
And I will call the column name like this $data->getDateConverter("created_at");