Compare commits
3 Commits
953a6b3631
...
1491d8b425
Author | SHA1 | Date |
---|---|---|
aslan | 1491d8b425 | |
aslan | 00266b9fa0 | |
aslan | 3ef7a84f7e |
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
namespace App\Http\Controllers\Catalog;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\StoreEducationalInstitutionRequest;
|
||||
use App\Http\Requests\UpdateEducationalInstitutionRequest;
|
||||
use App\Models\EducationalInstitution;
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
namespace App\Http\Controllers\Catalog;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\StoreFacultyRequest;
|
||||
use App\Http\Requests\UpdateFacultyRequest;
|
||||
use App\Models\Department;
|
||||
use App\Models\EducationalInstitution;
|
||||
use App\Models\Faculty;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
|
@ -39,6 +41,11 @@ class FacultyController extends Controller
|
|||
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
|
||||
{
|
||||
$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');
|
||||
}
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
@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
|
|
@ -22,8 +22,8 @@
|
|||
@foreach($faculties as $faculty)
|
||||
<tr class="">
|
||||
<th scope="row">{{ $faculty->position }}</th>
|
||||
<td>{{ $faculty->name }}</td>
|
||||
<td>{{ $faculty->description }}</td>
|
||||
<td><a href="{{ route('faculties.show', $faculty) }}">{{ $faculty->name }}</a></td>
|
||||
<td>{{ Str::words($faculty->description, 10, '...') }}</td>
|
||||
<td>{{ $faculty->educationalInstitution->name }}</td>
|
||||
<td><a href="{{ route("faculties.edit", $faculty) }}"
|
||||
class="btn btn-secondary">редактировать</a>
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
@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
|
|
@ -61,9 +61,10 @@
|
|||
<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>
|
||||
<li class="list-group-item"><a href="{{ route('departments.index') }}">Кафедры</a></li>
|
||||
</ul>
|
||||
</aside>
|
||||
<div class="col-10">@yield('content')</div>
|
||||
<main class="col-10">@yield('content')</main>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue