Hi there!
I have an Event model, a Customer model, and Location model.
Events have a customer_id and a location_id.
Locations have a customer_id and a timezone.
Currently, I’m grabbing all events with their location relation, then only after getting those, filtering down the collection of events by the event start date translated into the location’s timezone.
Looks basically like this
$allEvents = Event::where('customer_id', $customer->getId())
->with('location')
->get();
$events = $allEvents->filter(function($event) {
$start = $event->start_date->tz($event->location->getTimezone())->toDateString();
$today = Carbon::now()->tz($event->location->getTimezone())->toDateString;
return $start === $today;
});
This is not ideal, as the number of events will continue to grow.
Is there a way for me to query the events by start_date, but using the location relation's TZ version instead of the UTC version stored on the event? Kind of feels like a cart-before-the-horse issue, but figured I'd ask ;)