Roman_applicant-site/app/Http/Controllers/Catalog/EducationalInstitutionContr...

71 lines
2.5 KiB
PHP
Raw Permalink Normal View History

2024-02-07 10:18:46 +03:00
<?php
namespace App\Http\Controllers\Catalog;
2024-02-07 10:18:46 +03:00
use App\Http\Controllers\Controller;
2024-02-07 10:18:46 +03:00
use App\Http\Requests\StoreEducationalInstitutionRequest;
use App\Http\Requests\UpdateEducationalInstitutionRequest;
use App\Models\EducationalInstitution;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Foundation\Application;
class EducationalInstitutionController extends Controller
{
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
$educationalInstitutions = EducationalInstitution::all();
2024-02-07 16:34:04 +03:00
return view('catalog.educational-institution.index', compact('educationalInstitutions'));
2024-02-07 10:18:46 +03:00
}
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
2024-02-07 16:34:04 +03:00
return view('catalog.educational-institution.create');
2024-02-07 10:18:46 +03:00
}
public function store(StoreEducationalInstitutionRequest $request)
{
$validated = $request->validated();
$educationalInstitution = new EducationalInstitution();
$educationalInstitution->name = $validated['name'];
$educationalInstitution->description = $validated['description'];
$educationalInstitution->position = $validated['position'];
$educationalInstitution->save();
return redirect()->route('educational-institutions.index');
}
public function show(EducationalInstitution $educationalInstitution)
{
2024-02-07 16:34:04 +03:00
return view('catalog.educational-institution.show', compact('educationalInstitution'));
2024-02-07 10:18:46 +03:00
}
public function edit(EducationalInstitution $educationalInstitution)
{
2024-02-07 16:34:04 +03:00
return view('catalog.educational-institution.edit', compact('educationalInstitution'));
2024-02-07 10:18:46 +03:00
}
public function update(UpdateEducationalInstitutionRequest $request, EducationalInstitution $educationalInstitution)
{
$validated = $request->validated();
$educationalInstitution->name = $validated['name'];
$educationalInstitution->description = $validated['description'];
$educationalInstitution->position = $validated['position'];
$educationalInstitution->save();
return redirect()->route('educational-institutions.index');
}
public function destroy(EducationalInstitution $educationalInstitution)
{
2024-02-07 16:34:04 +03:00
if ($educationalInstitution->faculties()->exists()) {
return back();
}
2024-02-07 10:18:46 +03:00
$educationalInstitution->delete();
return redirect()->route('educational-institutions.index');
}
}