is_admin) abort(403); $students = Student::orderBy('last_name')->orderBy('first_name')->paginate(15); return view('admin.students.index', ['students' => $students]); } public function create() { if (! Auth::user()->is_admin) abort(403); $minGrade = Audition::min('minimum_grade'); $maxGrade = Audition::max('maximum_grade'); $schools = School::orderBy('name')->get(); return view('admin.students.create',['schools' => $schools, 'minGrade' => $minGrade, 'maxGrade' => $maxGrade]); } public function store() { if (! Auth::user()->is_admin) abort(403); request()->validate([ 'first_name' => ['required'], 'last_name' => ['required'], 'grade' => ['required', 'integer'], 'school_id' => ['required', 'exists:schools,id'] ]); $student = Student::create([ 'first_name' => request('first_name'), 'last_name' => request('last_name'), 'grade' => request('grade'), 'school_id' => request('school_id') ]); return redirect('/admin/students'); } public function edit(Student $student) { if (! Auth::user()->is_admin) abort(403); $minGrade = Audition::min('minimum_grade'); $maxGrade = Audition::max('maximum_grade'); $schools = School::orderBy('name')->get(); return view('admin.students.edit', ['student' => $student, 'schools' => $schools, 'minGrade' => $minGrade, 'maxGrade' => $maxGrade]); } public function update(Request $request, Student $student) { if (! Auth::user()->is_admin) abort(403); request()->validate([ 'first_name' => ['required'], 'last_name' => ['required'], 'grade' => ['required', 'integer'], 'school_id' => ['required', 'exists:schools,id'] ]); $student->update([ 'first_name' => request('first_name'), 'last_name' => request('last_name'), 'grade' => request('grade'), 'school_id' => request('school_id') ]); return redirect('/admin/students'); // TODO if a students grade is changed, we need to be sure they are still eligible for the auditions in which they are entered. } }