/** * Display a listing of the resource. * * @return Response */ public function index(Request $request) { $range = []; // Add "From" date to query $range[] = Carbon::parse($request->input('start'))->toDateTimeString(); // Add "To" date to query $range[] = Carbon::parse($request->input('end'))->toDateTimeString(); return Event::whereBetween('start_time', $range)->where('hidden', false)->get(); }
/** * Gets upcoming events for specified days. Defaults to 3 days * * @return array */ protected function getUpcomingEvents($days = 3) { $events = Event::whereBetween('start_time', [Carbon::now('America/Los_Angeles')->setTimezone('UTC'), Carbon::now('America/Los_Angeles')->addDays(2)->endOfDay()->setTimezone('UTC')])->get()->sortBy('start_time')->groupBy(function ($date) { return Carbon::parse($date->start_time, 'UTC')->setTimezone('America/Los_Angeles')->format('l'); // grouping data by day }); $result = []; // Get events for the next 3 days (including nulls) $date = Carbon::now('America/Los_Angeles'); for ($i = 0; $i < $days; $i++) { $day = $date->format('l'); // Set day or null if not found $result[$day] = isset($events[$day]) ? $events[$day] : null; $date->addDay(); } return $result; }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($slug) { // TODO Add a comments feed for each event. $event = Event::findBySlug($slug); // Check if exists if (!$event) { abort(404); } $event->load('creator', 'chair', 'registrations', 'guests'); // Look for events in the upcoming week $range = [Carbon::now(), Carbon::now()->addDays(6)]; $upcoming_events = Event::whereBetween('start_time', $range)->get()->sortBy('start_time')->groupBy(function ($date) { return Carbon::parse($date->start_time)->timezone('UTC')->setTimezone('America/Los_Angeles')->format('l'); // grouping data by day }); return view('pages.event', compact('event', 'upcoming_events')); }