drawService = $drawService; } public function index(Request $request) { $events = Event::with('auditions.flags')->get(); // $drawnAuditionsExist is true if any audition->hasFlag('drawn') is true $drawnAuditionsExist = Audition::whereHas('flags', function ($query) { $query->where('flag_name', 'drawn'); })->exists(); return view('admin.draw.index', compact('events', 'drawnAuditionsExist')); } public function store(RunDrawRequest $request) { // Request will contain audition which is an array of audition IDs all with a value of 1 // Code below results in a collection of auditions that were checked on the form $auditions = Audition::with('flags')->findMany(array_keys($request->input('audition', []))); if ($this->drawService->checkCollectionForDrawnAuditions($auditions)) { return to_route('admin.draw.index')->with('error', 'Cannot run draw. Some auditions have already been drawn.'); } app(RunDraw::class)($auditions); return to_route('admin.draw.index')->with('success', 'Draw completed successfully'); } /** * generates the page with checkboxes for each drawn audition with an intent to clear them */ public function edit(Request $request) { $drawnAuditions = Audition::whereHas('flags', function ($query) { $query->where('flag_name', 'drawn'); })->get(); return view('admin.draw.edit', compact('drawnAuditions')); } /** * Clears the draw for auditions */ public function destroy(ClearDrawRequest $request) { // Request will contain audition which is an array of audition IDs all with a value of 1 // Code below results in a collection of auditions that were checked on the form $auditions = Audition::with('flags')->findMany(array_keys($request->input('audition', []))); $this->drawService->clearDrawsOnCollection($auditions); return to_route('admin.draw.index')->with('success', 'Draws cleared successfully'); } }