CourseWork/app/Http/Controllers/GradeController.php

105 lines
2.4 KiB
PHP
Raw Normal View History

2024-04-16 13:27:51 +04:00
<?php
namespace App\Http\Controllers;
use App\Http\Requests\GradePostRequest;
use App\Models\Grade;
2024-04-17 10:11:31 +04:00
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;
2024-04-16 13:27:51 +04:00
class GradeController extends Controller
{
/**
* Display a listing of the resource.
*/
2024-04-17 10:11:31 +04:00
public function index(): View
2024-04-16 13:27:51 +04:00
{
2024-06-22 23:59:16 +04:00
if(request()->user()->cannot('viewAny', Grade::class)) {
abort(403);
}
2024-04-16 13:27:51 +04:00
return view('grades.index', [
2024-06-16 00:41:31 +04:00
'grades' => Grade::filter()->paginate(5)->withQueryString(),
2024-04-16 13:27:51 +04:00
]);
}
/**
* Show the form for creating a new resource.
*/
2024-04-17 10:11:31 +04:00
public function create(): View
2024-04-16 13:27:51 +04:00
{
2024-06-22 23:59:16 +04:00
if(request()->user()->cannot('create', Grade::class)) {
abort(403);
}
2024-04-16 13:27:51 +04:00
return view('grades.create');
}
/**
* Store a newly created resource in storage.
*/
2024-04-17 10:11:31 +04:00
public function store(GradePostRequest $request): RedirectResponse
2024-04-16 13:27:51 +04:00
{
2024-06-22 23:59:16 +04:00
if(request()->user()->cannot('create', Grade::class)) {
abort(403);
}
2024-06-16 00:41:31 +04:00
return redirect()->route('grades.show', Grade::create($request->validated()));
2024-04-16 13:27:51 +04:00
}
/**
* Display the specified resource.
*/
2024-04-17 10:11:31 +04:00
public function show(Grade $grade): View
2024-04-16 13:27:51 +04:00
{
2024-06-22 23:59:16 +04:00
if(request()->user()->cannot('view', $grade)) {
abort(403);
}
2024-04-16 13:27:51 +04:00
return view('grades.show', [
2024-05-06 17:51:16 +04:00
'grade' => $grade,
2024-05-07 12:14:18 +04:00
'subjects' => $grade->subjects,
2024-04-16 13:27:51 +04:00
]);
}
/**
* Show the form for editing the specified resource.
*/
2024-04-17 10:11:31 +04:00
public function edit(Grade $grade): View
2024-04-16 13:27:51 +04:00
{
2024-06-22 23:59:16 +04:00
if(request()->user()->cannot('update', Grade::class)) {
abort(403);
}
2024-04-16 13:27:51 +04:00
return view('grades.edit', [
'grade' => $grade,
]);
}
/**
* Update the specified resource in storage.
*/
2024-04-17 10:11:31 +04:00
public function update(GradePostRequest $request, Grade $grade): RedirectResponse
2024-04-16 13:27:51 +04:00
{
2024-06-22 23:59:16 +04:00
if(request()->user()->cannot('update', Grade::class)) {
abort(403);
}
2024-06-16 00:41:31 +04:00
return redirect()->route('grades.show', $grade->update($request->validated()));
2024-04-16 13:27:51 +04:00
}
/**
* Remove the specified resource from storage.
*/
2024-04-17 10:11:31 +04:00
public function destroy(Grade $grade): RedirectResponse
2024-04-16 13:27:51 +04:00
{
2024-06-22 23:59:16 +04:00
if(request()->user()->cannot('delete', Grade::class)) {
abort(403);
}
2024-06-16 00:41:31 +04:00
$grade->delete();
2024-04-16 13:27:51 +04:00
return redirect()->route('grades.index');
}
}