is_admin) { abort(403); } $rooms = Room::with('auditions.entries')->orderBy('name')->get(); return view('admin.rooms.index', ['rooms' => $rooms]); } public function judgingAssignment() // Show form for assigning judges { if (! Auth::user()->is_admin) { abort(403); } $usersWithoutRooms = User::doesntHave('rooms')->orderBy('last_name')->orderBy('first_name')->get(); $usersWithRooms = User::has('rooms')->orderBy('last_name')->orderBy('first_name')->get(); $rooms = Room::with(['judges.school', 'auditions'])->get(); return view('admin.rooms.judge_assignments', compact('usersWithoutRooms', 'usersWithRooms', 'rooms')); } public function updateJudgeAssignment(Request $request, Room $room) { if (! Auth::user()->is_admin) { abort(403); } $validData = $request->validate([ 'judge' => 'exists:users,id', ]); $judge = User::find($validData['judge']); if ($request->isMethod('post')) { // attach judge on post $room->addJudge($judge->id); $message = 'Assigned '.$judge->full_name().' to '.$room->name; } elseif ($request->isMethod('delete')) { // detach judge on delete $room->removeJudge($judge->id); $message = 'Removed '.$judge->full_name().' from '.$room->name; } else { return redirect('/admin/rooms/judging_assignments')->with('error', 'Invalid request method.'); } return redirect('/admin/rooms/judging_assignments')->with('success', $message); } public function create() { if (! Auth::user()->is_admin) { abort(403); } return view('admin.rooms.create'); } public function store(Request $request) { if (! Auth::user()->is_admin) { abort(403); } $validData = $request->validate([ 'name' => 'required', 'description' => 'nullable', ]); $room = new Room(); $room->name = $validData['name']; $room->description = $validData['description']; $room->save(); return redirect()->route('admin.rooms.index')->with('success', 'Room created.'); } public function update(Request $request, Room $room) { if (! Auth::user()->is_admin) { abort(403); } $validData = $request->validate([ 'name' => 'required', 'description' => 'nullable', ]); $room->name = $validData['name']; $room->description = $validData['description']; $room->save(); return redirect()->route('admin.rooms.index')->with('success', 'Room updated.'); } public function destroy(Room $room) { if (! Auth::user()->is_admin) { abort(403); } if ($room->auditions()->count() > 0) { return redirect()->route('admin.rooms.index')->with('error', 'Cannot delete room with auditions. First move the auditions to unassigned or another room'); } $room->delete(); return redirect()->route('admin.rooms.index')->with('success', 'Room deleted.'); } }