By default my laravel app is storing the dates in UTC timezone and depending on the user profile I am changing the timezone via Model accessor and everything is working fine.
The only issue is with DB::raw queries where the timezone is not changing. Here is the example of my query
$sales=Sales::select(DB::raw('hour(created_at) AS hour'), DB::raw('COUNT(id) AS sales'))
->where('created_at','>=',Carbon::now()->startOfDay())
->get()->groupBy(function($data) use($timezone){
return Carbon::parse($data->created_at)->timezone($timezone)->format('H');
});
Now here the hour is coming in UTC timezone instead of user timezone. How can I get the hour in user timezone here?