71 lines
2.0 KiB
PHP
71 lines
2.0 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers\admin\Catalog\Direction;
|
||
|
|
||
|
use App\Http\Controllers\Controller;
|
||
|
use App\Http\Requests\admin\Catalog\Direction\StoreSubjectRequest;
|
||
|
use App\Http\Requests\admin\Catalog\Direction\UpdateSubjectRequest;
|
||
|
use App\Models\Subject;
|
||
|
use Illuminate\Contracts\View\View;
|
||
|
use Illuminate\Http\RedirectResponse;
|
||
|
|
||
|
class SubjectController extends Controller
|
||
|
{
|
||
|
public function index(): View
|
||
|
{
|
||
|
$subjects = Subject::all();
|
||
|
return view('admin.catalog.direction.subject.index', compact('subjects'));
|
||
|
}
|
||
|
|
||
|
public function create(): View
|
||
|
{
|
||
|
return view('admin.catalog.direction.subject.create');
|
||
|
}
|
||
|
|
||
|
public function store(StoreSubjectRequest $request): RedirectResponse
|
||
|
{
|
||
|
$validated = $request->validated();
|
||
|
|
||
|
$subject = new Subject();
|
||
|
$subject->name = $validated['name'];
|
||
|
$subject->description = $validated['description'];
|
||
|
$subject->slug = $validated['slug'];
|
||
|
$subject->position = $validated['position'];
|
||
|
$subject->save();
|
||
|
|
||
|
return redirect()->route('subjects.index');
|
||
|
}
|
||
|
|
||
|
public function show(Subject $subject): View
|
||
|
{
|
||
|
return view('admin.catalog.direction.subject.show', compact('subject'));
|
||
|
}
|
||
|
|
||
|
public function edit(Subject $subject): View
|
||
|
{
|
||
|
return view('admin.catalog.direction.subject.edit', compact('subject'));
|
||
|
}
|
||
|
|
||
|
public function update(UpdateSubjectRequest $request, Subject $subject): RedirectResponse
|
||
|
{
|
||
|
$validated = $request->validated();
|
||
|
|
||
|
$subject->name = $validated['name'];
|
||
|
$subject->description = $validated['description'];
|
||
|
$subject->slug = $validated['slug'];
|
||
|
$subject->position = $validated['position'];
|
||
|
$subject->save();
|
||
|
|
||
|
return redirect()->route('subjects.index');
|
||
|
}
|
||
|
|
||
|
public function destroy(Subject $subject): RedirectResponse
|
||
|
{
|
||
|
if ($subject->entranceExaminations()->exists()) {
|
||
|
return back();
|
||
|
}
|
||
|
$subject->delete();
|
||
|
return redirect()->route('subjects.index');
|
||
|
}
|
||
|
}
|