Roman_applicant-site/app/Http/Controllers/FacultyController.php

67 lines
2.3 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Http\Requests\StoreFacultyRequest;
use App\Http\Requests\UpdateFacultyRequest;
use App\Models\EducationalInstitution;
use App\Models\Faculty;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Foundation\Application;
use Illuminate\Http\RedirectResponse;
class FacultyController extends Controller
{
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
$faculties = Faculty::all();
return view('catalog.faculty.index', compact('faculties'));
}
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
$educationalInstitutions = EducationalInstitution::pluck('name', 'id');
return view('catalog.faculty.create', compact('educationalInstitutions'));
}
public function store(StoreFacultyRequest $request): RedirectResponse
{
$validated = $request->validated();
$faculty = new Faculty();
$faculty->name = $validated['name'];
$faculty->description = $validated['description'];
$faculty->position = $validated['position'];
$faculty->educational_institution_id = $validated['educational_institution_id'];
$faculty->save();
return redirect()->route('faculties.index');
}
public function edit(Faculty $faculty): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
$educationalInstitutions = EducationalInstitution::pluck('name', 'id');
return view('catalog.faculty.edit', compact('faculty', 'educationalInstitutions'));
}
public function update(UpdateFacultyRequest $request, Faculty $faculty): RedirectResponse
{
$validated = $request->validated();
$faculty->name = $validated['name'];
$faculty->description = $validated['description'];
$faculty->position = $validated['position'];
$faculty->educational_institution_id = $validated['educational_institution_id'];
$faculty->save();
return redirect()->route('faculties.index');
}
public function destroy(Faculty $faculty): RedirectResponse
{
$faculty->delete();
return redirect()->route('faculties.index');
}
}