When returning Laravel results to the user, the time zone is displayed incorrectly.
<p>I have a Laravel API and the application's timezone is set to UTC. MySQL's time zone is set to SYSTEM, which is also expressed as UTC. I also have a column in the users table that stores the user's time zone information. <br /><br />My front-end interface has a field where the user can enter a date/time as the time of a certain process, and this time will be sent to the API in the user's time zone. So when that record is saved, I convert it to UTC and then insert it into the database like this; </p><p><br /></p>
<pre class="brush:php;toolbar:false;">auth()->user()->procedure()->create([
'procedure_time' => Carbon::parse($request->procedure_time, auth()->user()->timezone)->setTimezone('UTC'),
]);
</pre>
<p>I'm trying to get records of all user processes for the current day in the current user's time zone and return those results to the frontend. I thought the results were correct, but when my computer got to midnight, the results were still showing as records from the previous day for about 10 hours or so. This is how I try to return these results;</p>
<pre class="brush:php;toolbar:false;">$todayProcedures = Procedure::query()
->where('user_id', $user->id)
->whereDate('procedure_time', '>=', Carbon::now()->startOfDay()->tz($user->timezone))
->whereDate('procedure_time', '<=', Carbon::now()->endOfDay()->tz($user->timezone))
->get();
</pre>
<p>I can't figure out where I went wrong. </p>