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