In Laravel 5.3, I've written a collection designed to cycle through a user's bills and determine whether they were paid within a given time frame.
return $dates->map(function ($item, $key) use ($interval) {
$bills = DB::table('bills')
->where('provider_id', Auth::user()->company()->first()->id)
->whereBetween(
'date_paid', [$item, $this->returnRangeFromInterval($item, $interval)]
)
->where('status', 'paid')
->get();
return $bills->pluck('amount_due')->sum();
});
That date_paid
attribute is stored as UTC, but to return an accurate sum, I need to shift that date to a user's timezone—which I have stored on the User
object. How could I accomplish this in the collection above?
It looks as though I can use a MYSQL method called convert_tz if absolutely necessary, but I'm interested first and foremost in the "Laravel Way".