user()->cannot('viewAny', Teacher::class)) { abort(403); } return view('teachers.index', [ 'teachers' => Teacher::filter()->paginate(5)->withQueryString(), ]); } /** * Show the form for creating a new resource. */ public function create(): View { if(request()->user()->cannot('create', Teacher::class)) { abort(403); } return view('teachers.create'); } /** * Store a newly created resource in storage. */ public function store(TeacherPostRequest $request): RedirectResponse { if(request()->user()->cannot('create', Teacher::class)) { abort(403); } return redirect()->route( 'teachers.show', $this->service->create($request->validated()) ); } /** * Display the specified resource. */ public function show(Teacher $teacher): View { if(request()->user()->cannot('view', $teacher)) { abort(403); } return view('teachers.show', [ 'teacher' => $teacher, 'subjects' => $teacher->subjects, ]); } /** * Show the form for editing the specified resource. */ public function edit(Teacher $teacher): View { if(request()->user()->cannot('update', $teacher)) { abort(403); } return view('teachers.edit', [ 'teacher' => $teacher, ]); } /** * Update the specified resource in storage. */ public function update(TeacherPostRequest $request, Teacher $teacher): RedirectResponse { if(request()->user()->cannot('update', $teacher)) { abort(403); } return redirect()->route( 'teachers.show', $this->service->update($teacher, $request->validated()) ); } /** * Remove the specified resource from storage. */ public function destroy(Teacher $teacher): RedirectResponse { if(request()->user()->cannot('update', $teacher)) { abort(403); } $teacher->user()->delete(); $teacher->delete(); return redirect()->route('teachers.index'); } }