Compare commits

..

3 Commits

Author SHA1 Message Date
aslan 1491d8b425 Merge remote-tracking branch 'origin/main'
Tests & Lint & Deploy to Railway / build (20.x, 8.3) (push) Successful in 2m22s Details
Tests & Lint & Deploy to Railway / deploy (push) Successful in 24s Details
2024-02-08 16:01:46 +03:00
aslan 00266b9fa0 Refactoring Faculty and Education Institution views 2024-02-08 16:01:40 +03:00
aslan 3ef7a84f7e add Department resource 2024-02-08 16:00:06 +03:00
7 changed files with 106 additions and 5 deletions

View File

@ -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;

View File

@ -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');
}

View File

@ -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');
}
}

View File

@ -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

View File

@ -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>

View File

@ -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

View File

@ -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>