Compare commits

..

No commits in common. "1491d8b425bfa9e21c3a93e09e091292a838d3dd" and "953a6b3631ebd41f7540c38a4a8f19930b18a09d" have entirely different histories.

7 changed files with 5 additions and 106 deletions

View File

@ -1,8 +1,7 @@
<?php <?php
namespace App\Http\Controllers\Catalog; namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreEducationalInstitutionRequest; use App\Http\Requests\StoreEducationalInstitutionRequest;
use App\Http\Requests\UpdateEducationalInstitutionRequest; use App\Http\Requests\UpdateEducationalInstitutionRequest;
use App\Models\EducationalInstitution; use App\Models\EducationalInstitution;

View File

@ -1,11 +1,9 @@
<?php <?php
namespace App\Http\Controllers\Catalog; namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreFacultyRequest; use App\Http\Requests\StoreFacultyRequest;
use App\Http\Requests\UpdateFacultyRequest; use App\Http\Requests\UpdateFacultyRequest;
use App\Models\Department;
use App\Models\EducationalInstitution; use App\Models\EducationalInstitution;
use App\Models\Faculty; use App\Models\Faculty;
use Illuminate\Contracts\View\Factory; use Illuminate\Contracts\View\Factory;
@ -41,11 +39,6 @@ class FacultyController extends Controller
return redirect()->route('faculties.index'); return redirect()->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 public function edit(Faculty $faculty): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{ {
$educationalInstitutions = EducationalInstitution::pluck('name', 'id'); $educationalInstitutions = EducationalInstitution::pluck('name', 'id');
@ -67,9 +60,6 @@ class FacultyController extends Controller
public function destroy(Faculty $faculty): RedirectResponse public function destroy(Faculty $faculty): RedirectResponse
{ {
if ($faculty->departments()->exists()) {
return back();
}
$faculty->delete(); $faculty->delete();
return redirect()->route('faculties.index'); return redirect()->route('faculties.index');
} }

View File

@ -5,7 +5,6 @@ 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\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Faculty extends Model class Faculty extends Model
{ {
@ -22,9 +21,4 @@ class Faculty extends Model
{ {
return $this->belongsTo(EducationalInstitution::class); return $this->belongsTo(EducationalInstitution::class);
} }
public function departments(): HasMany
{
return $this->hasMany('App\Models\Department', 'faculty_id');
}
} }

View File

@ -1,64 +0,0 @@
@extends('layouts.admin-layout')
@section('content')
@auth()
<div class="row">
<div class="col">
<h1 class=""> Создать кафедру</h1>
{{ Form::open(['url' => route('departments.update', $department), 'method' => 'PATCH', 'class' => '']) }}
<div class="col">
<div class="mt-3">
{{ Form::label('position', 'Позиция') }}
</div>
<div class="mt-1">
{{ Form::text('position', $department->position, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('position') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('name', 'Название') }}
</div>
<div class="mt-1">
{{ Form::text('name', $department->name, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('name') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('description', 'Описание') }}
</div>
<div class="mt-1">
{{ Form::text('description', $department->description, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('description') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('educational_institution_id', 'Факультет') }}
</div>
<div class="mt-1">
{{ Form::select('faculty_id', $faculties, $department->faculty->id, ['class' => 'form-select']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('educational_institution_id') }}
@endif
</div>
<div class="mt-3">
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
</div>
</div>
{{ Form::close() }}
</div>
</div>
@endauth
@endsection

View File

@ -22,8 +22,8 @@
@foreach($faculties as $faculty) @foreach($faculties as $faculty)
<tr class=""> <tr class="">
<th scope="row">{{ $faculty->position }}</th> <th scope="row">{{ $faculty->position }}</th>
<td><a href="{{ route('faculties.show', $faculty) }}">{{ $faculty->name }}</a></td> <td>{{ $faculty->name }}</td>
<td>{{ Str::words($faculty->description, 10, '...') }}</td> <td>{{ $faculty->description }}</td>
<td>{{ $faculty->educationalInstitution->name }}</td> <td>{{ $faculty->educationalInstitution->name }}</td>
<td><a href="{{ route("faculties.edit", $faculty) }}" <td><a href="{{ route("faculties.edit", $faculty) }}"
class="btn btn-secondary">редактировать</a> class="btn btn-secondary">редактировать</a>

View File

@ -1,19 +0,0 @@
@extends('layouts.admin-layout')
@section('content')
@auth()
<h6><a href="{{ route('educational-institutions.show', $faculty->educationalInstitution) }}">{{ $faculty->educationalInstitution->name }}</a> -> {{ $faculty->name }}</h6>
<div class="container mt-4">
<h2>Название</h2>
<p>{{ $faculty->name }}</p>
<h2>Описание</h2>
<p>{{ $faculty->description }}</p>
<h2>Позиция</h2>
<p>{{ $faculty->position }}</p>
<h2>Кафедры</h2>
@foreach($faculty->departments as $department)
<p><a href="{{ route('departments.show', $department) }}">{{ $department->name }}</a></p>
@endforeach
</div>
@endauth
@endsection

View File

@ -61,10 +61,9 @@
<li class="list-group-item"><a href="{{ route('educational-institutions.index') }}">Учебные <li class="list-group-item"><a href="{{ route('educational-institutions.index') }}">Учебные
заведения</a></li> заведения</a></li>
<li class="list-group-item"><a href="{{ route('faculties.index') }}">Факультеты</a></li> <li class="list-group-item"><a href="{{ route('faculties.index') }}">Факультеты</a></li>
<li class="list-group-item"><a href="{{ route('departments.index') }}">Кафедры</a></li>
</ul> </ul>
</aside> </aside>
<main class="col-10">@yield('content')</main> <div class="col-10">@yield('content')</div>
</div> </div>
</div> </div>