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

67 lines
2.2 KiB
PHP
Raw Normal View History

2024-02-07 16:30:49 +03:00
<?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)
{
$educationalInstitutions = EducationalInstitution::pluck('name', 'id');
return view('catalog.faculty.edit', compact('faculty', 'educationalInstitutions'));
}
public function update(UpdateFacultyRequest $request, Faculty $faculty)
{
$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)
{
$faculty->delete();
return redirect()->route('faculties.index');
}
}