diff --git a/app/Http/Controllers/EducationalInstitutionController.php b/app/Http/Controllers/Catalog/EducationalInstitutionController.php similarity index 96% rename from app/Http/Controllers/EducationalInstitutionController.php rename to app/Http/Controllers/Catalog/EducationalInstitutionController.php index 8da1451..ebdb5fe 100644 --- a/app/Http/Controllers/EducationalInstitutionController.php +++ b/app/Http/Controllers/Catalog/EducationalInstitutionController.php @@ -1,7 +1,8 @@ route('faculties.index'); } + public function show(Faculty $faculty): View|Application|Factory|\Illuminate\Contracts\Foundation\Application + { + return view('catalog.faculty.show', compact('faculty')); + } + public function edit(Faculty $faculty): View|Application|Factory|\Illuminate\Contracts\Foundation\Application { $educationalInstitutions = EducationalInstitution::pluck('name', 'id'); @@ -60,6 +67,9 @@ class FacultyController extends Controller public function destroy(Faculty $faculty): RedirectResponse { + if ($faculty->departments()->exists()) { + return back(); + } $faculty->delete(); return redirect()->route('faculties.index'); } diff --git a/app/Models/Faculty.php b/app/Models/Faculty.php index 5568657..5f65286 100644 --- a/app/Models/Faculty.php +++ b/app/Models/Faculty.php @@ -5,6 +5,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasMany; class Faculty extends Model { @@ -21,4 +22,9 @@ class Faculty extends Model { return $this->belongsTo(EducationalInstitution::class); } + + public function departments(): HasMany + { + return $this->hasMany('App\Models\Department', 'faculty_id'); + } } diff --git a/resources/views/catalog/faculty/index.blade.php b/resources/views/catalog/faculty/index.blade.php index 8ccea3c..9bf0f19 100644 --- a/resources/views/catalog/faculty/index.blade.php +++ b/resources/views/catalog/faculty/index.blade.php @@ -22,8 +22,8 @@ @foreach($faculties as $faculty)
{{ $faculty->name }}
+{{ $faculty->description }}
+{{ $faculty->position }}
+