2024-04-17 10:11:31 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Http\Requests\SubjectPostRequest;
|
|
|
|
use App\Models\Subject;
|
2024-06-23 00:06:14 +04:00
|
|
|
|
2024-06-22 23:59:16 +04:00
|
|
|
use App\Services\SubjectService;
|
2024-06-17 17:38:29 +04:00
|
|
|
use App\Services\FileService;
|
2024-04-17 10:11:31 +04:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use Illuminate\View\View;
|
|
|
|
|
|
|
|
class SubjectController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*/
|
2024-06-22 23:59:16 +04:00
|
|
|
public function index(SubjectService $service): View
|
2024-04-17 10:11:31 +04:00
|
|
|
{
|
|
|
|
return view('subjects.index', [
|
2024-06-22 23:59:16 +04:00
|
|
|
'subjects' => $service->getSubjects(),
|
2024-04-17 10:11:31 +04:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*/
|
|
|
|
public function create(): View
|
|
|
|
{
|
2024-06-22 23:59:16 +04:00
|
|
|
if(request()->user()->cannot('create', Subject::class)) {
|
|
|
|
abort(403);
|
|
|
|
}
|
|
|
|
|
2024-04-17 10:11:31 +04:00
|
|
|
return view('subjects.create');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*/
|
|
|
|
public function store(SubjectPostRequest $request): RedirectResponse
|
|
|
|
{
|
2024-06-22 23:59:16 +04:00
|
|
|
if(request()->user()->cannot('create', Subject::class)) {
|
|
|
|
abort(403);
|
|
|
|
}
|
|
|
|
|
2024-04-23 14:52:49 +04:00
|
|
|
return redirect()->route(
|
|
|
|
'subjects.show',
|
2024-06-16 12:20:48 +04:00
|
|
|
Subject::create($request->validated()),
|
2024-04-23 14:52:49 +04:00
|
|
|
);
|
2024-04-17 10:11:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*/
|
|
|
|
public function show(Subject $subject): View
|
|
|
|
{
|
|
|
|
return view('subjects.show', [
|
2024-05-06 17:51:16 +04:00
|
|
|
'subject' => $subject,
|
2024-04-17 10:11:31 +04:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*/
|
|
|
|
public function edit(Subject $subject): View
|
|
|
|
{
|
2024-06-22 23:59:16 +04:00
|
|
|
if(request()->user()->cannot('update', $subject)) {
|
|
|
|
abort(403);
|
|
|
|
}
|
|
|
|
|
2024-04-17 10:11:31 +04:00
|
|
|
return view('subjects.edit', [
|
|
|
|
'subject' => $subject,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*/
|
|
|
|
public function update(SubjectPostRequest $request, Subject $subject): RedirectResponse
|
|
|
|
{
|
2024-06-22 23:59:16 +04:00
|
|
|
if(request()->user()->cannot('update', $subject)) {
|
|
|
|
abort(403);
|
|
|
|
}
|
|
|
|
|
2024-06-25 00:52:48 +04:00
|
|
|
$subject->update($request->validated());
|
|
|
|
|
|
|
|
return redirect()->route('subjects.show', $subject);
|
2024-04-17 10:11:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*/
|
|
|
|
public function destroy(Subject $subject): RedirectResponse
|
|
|
|
{
|
2024-06-22 23:59:16 +04:00
|
|
|
if(request()->user()->cannot('delete', $subject)) {
|
|
|
|
abort(403);
|
|
|
|
}
|
|
|
|
|
2024-06-16 12:20:48 +04:00
|
|
|
$subject->delete();
|
2024-04-17 10:11:31 +04:00
|
|
|
|
|
|
|
return redirect()->route('subjects.index');
|
|
|
|
}
|
2024-06-17 17:38:29 +04:00
|
|
|
|
|
|
|
public function exportToPDF(FileService $fileService)
|
|
|
|
{
|
|
|
|
return $fileService->exportSubjects();
|
|
|
|
}
|
2024-04-17 10:11:31 +04:00
|
|
|
}
|