refactored Educational Institutions

This commit is contained in:
aslan 2024-02-07 16:34:04 +03:00
parent 93592992b7
commit b11015ae8f
6 changed files with 30 additions and 9 deletions

View File

@ -14,12 +14,12 @@ class EducationalInstitutionController extends Controller
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{ {
$educationalInstitutions = EducationalInstitution::all(); $educationalInstitutions = EducationalInstitution::all();
return view('educational-institution.index', compact('educationalInstitutions')); return view('catalog.educational-institution.index', compact('educationalInstitutions'));
} }
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{ {
return view('educational-institution.create'); return view('catalog.educational-institution.create');
} }
public function store(StoreEducationalInstitutionRequest $request) public function store(StoreEducationalInstitutionRequest $request)
@ -37,12 +37,12 @@ class EducationalInstitutionController extends Controller
public function show(EducationalInstitution $educationalInstitution) public function show(EducationalInstitution $educationalInstitution)
{ {
return view('educational-institution.show', compact('educationalInstitution')); return view('catalog.educational-institution.show', compact('educationalInstitution'));
} }
public function edit(EducationalInstitution $educationalInstitution) public function edit(EducationalInstitution $educationalInstitution)
{ {
return view('educational-institution.edit', compact('educationalInstitution')); return view('catalog.educational-institution.edit', compact('educationalInstitution'));
} }
public function update(UpdateEducationalInstitutionRequest $request, EducationalInstitution $educationalInstitution) public function update(UpdateEducationalInstitutionRequest $request, EducationalInstitution $educationalInstitution)
@ -59,6 +59,9 @@ class EducationalInstitutionController extends Controller
public function destroy(EducationalInstitution $educationalInstitution) public function destroy(EducationalInstitution $educationalInstitution)
{ {
if ($educationalInstitution->faculties()->exists()) {
return back();
}
$educationalInstitution->delete(); $educationalInstitution->delete();
return redirect()->route('educational-institutions.index'); return redirect()->route('educational-institutions.index');

View File

@ -4,8 +4,21 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class EducationalInstitution extends Model class EducationalInstitution extends Model
{ {
use HasFactory; use HasFactory;
protected $fillable = [
'id',
'name',
'description',
'position',
];
public function faculties(): HasMany
{
return $this->hasMany('App\Models\Faculty', 'educational_institution_id');
}
} }

View File

@ -13,11 +13,12 @@
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</head> </head>
<body class="antialiased"> <body class="antialiased">
<div class="container"> <div class="container-fluid">
<header <header
class="d-flex flex-wrap align-items-center justify-content-center justify-content-md-between py-3 mb-4 border-bottom"> class="d-flex flex-wrap align-items-center justify-content-center justify-content-md-between py-3 mb-4 border-bottom">
<ul class="nav col-9 col-md-auto mb-2 justify-content-start mb-md-0"> <ul class="nav col-9 col-md-auto mb-2 justify-content-start mb-md-0">
<li><a href="{{ route('dashboard') }}" class="nav-link px-2 link-secondary text-wrap" style="width: 4rem;">Главная</a></li> <li><a href="{{ route('dashboard') }}" class="nav-link px-2 link-secondary text-wrap" style="width: 4rem;">Главная</a>
</li>
</ul> </ul>
@ -52,10 +53,14 @@
<li class="list-group-item"><a href="{{ route('files.index') }}">Файлы</a></li> <li class="list-group-item"><a href="{{ route('files.index') }}">Файлы</a></li>
<li class="list-group-item"><a href="{{ route('admin-reception-screen.index') }}">Экран Приема</a></li> <li class="list-group-item"><a href="{{ route('admin-reception-screen.index') }}">Экран Приема</a></li>
@if(!is_null(Auth::getUser()) && Auth::getUser()->name === 'admin') @if(!is_null(Auth::getUser()) && Auth::getUser()->name === 'admin')
{{-- <li class="list-group-item"></li>--}} <li class="list-group-item"></li>
<li class="list-group-item"><a href="{{ route('users.index') }}">Список администраторов</a></li> <li class="list-group-item"><a href="{{ route('users.index') }}">Список администраторов</a></li>
<li class="list-group-item"><a href="{{ route('educational-institutions.index') }}">Учебные заведения</a></li>
@endif @endif
<li class="list-group-item"></li>
<li class="list-group-item">Справочники</li>
<li class="list-group-item"><a href="{{ route('educational-institutions.index') }}">Учебные
заведения</a></li>
<li class="list-group-item"><a href="{{ route('faculties.index') }}">Факультеты</a></li>
</ul> </ul>
</aside> </aside>
<div class="col-10">@yield('content')</div> <div class="col-10">@yield('content')</div>