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 ($auditions->contains(fn ($audition) => $audition->hasFlag('drawn'))) { 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', []))); app(ClearDraw::class)($auditions); return to_route('admin.draw.index')->with('success', 'Draws cleared successfully'); } }