auditionService = $auditionService; } /** * Handle the incoming request. */ public function __invoke(Request $request) { $publishedAdvancementAuditions = []; $resultsAdvancementList = []; $publishedAuditions = Audition::seatsPublished() ->with('seats.ensemble') ->with('seats.entry.student') ->with('event.ensembles') ->orderBy('score_order')->get(); $resultsSeatList = Cache::rememberForever('resultsSeatList', function () use ($publishedAuditions) { $seatList = []; // Load the $seatList in the form of $seatlist[audition_id] is an array of seats for that audition // each $seatList[audition_id][] will contain a string with ensemble and seat number and the student object filling it foreach ($publishedAuditions as $audition) { $seats = $audition->seats->groupBy('ensemble_id'); $ensembles = $audition->event->ensembles; foreach ($ensembles as $ensemble) { if (! $seats->has($ensemble->id)) { // If there are no students seated in this ensemble, skip it continue; } foreach ($seats[$ensemble->id] as $seat) { /** @var Seat $seat */ $seatList[$audition->id][] = [ 'seat' => $ensemble->name.' '.$seat->seat, 'student' => $seat->entry->student, ]; } } } return $seatList; }); if (auditionSetting('advanceTo')) { $publishedAdvancementAuditions = Audition::advancementPublished()->orderBy('score_order')->get(); $resultsAdvancementList = Cache::rememberForever('resultsAdvancementList', function () { // get entries with a related flag of will_advance $advancingEntries = Entry::forAdvancement()->with('student.school') ->whereHas('flags', function ($query) { $query->where('flag_name', EntryFlags::WILL_ADVANCE); }) ->get(); $advancingEntries = $advancingEntries->sortBy(function ($entry) { return $entry->student->full_name(true); }); return $advancingEntries->groupBy('audition_id'); }); } return view('results.index', compact('publishedAuditions', 'resultsSeatList', 'publishedAdvancementAuditions', 'resultsAdvancementList')); } }