forked from aslan/applicant-site
Refactoring Faculty and Education Institution views
This commit is contained in:
parent
3ef7a84f7e
commit
00266b9fa0
|
@ -1,7 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers\Catalog;
|
||||||
|
|
||||||
|
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;
|
|
@ -1,9 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers\Catalog;
|
||||||
|
|
||||||
|
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;
|
||||||
|
@ -39,6 +41,11 @@ 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');
|
||||||
|
@ -60,6 +67,9 @@ 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');
|
||||||
}
|
}
|
|
@ -5,6 +5,7 @@ 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
|
||||||
{
|
{
|
||||||
|
@ -21,4 +22,9 @@ 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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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>{{ $faculty->name }}</td>
|
<td><a href="{{ route('faculties.show', $faculty) }}">{{ $faculty->name }}</a></td>
|
||||||
<td>{{ $faculty->description }}</td>
|
<td>{{ Str::words($faculty->description, 10, '...') }}</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>
|
||||||
|
|
|
@ -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') }}">Учебные
|
<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>
|
||||||
<div class="col-10">@yield('content')</div>
|
<main class="col-10">@yield('content')</main>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue