refactor educationalInstitution

This commit is contained in:
aslan 2024-02-07 19:27:25 +03:00
parent ebade01982
commit 941da60c6f
5 changed files with 34 additions and 9 deletions

View File

@ -39,13 +39,13 @@ class FacultyController extends Controller
return redirect()->route('faculties.index');
}
public function edit(Faculty $faculty)
public function edit(Faculty $faculty): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
$educationalInstitutions = EducationalInstitution::pluck('name', 'id');
return view('catalog.faculty.edit', compact('faculty', 'educationalInstitutions'));
}
public function update(UpdateFacultyRequest $request, Faculty $faculty)
public function update(UpdateFacultyRequest $request, Faculty $faculty): RedirectResponse
{
$validated = $request->validated();
@ -58,7 +58,7 @@ class FacultyController extends Controller
return redirect()->route('faculties.index');
}
public function destroy(Faculty $faculty)
public function destroy(Faculty $faculty): RedirectResponse
{
$faculty->delete();
return redirect()->route('faculties.index');

View File

@ -2,7 +2,9 @@
namespace App\Http\Requests;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpdateEducationalInstitutionRequest extends FormRequest
{
@ -17,14 +19,19 @@ class UpdateEducationalInstitutionRequest extends FormRequest
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
* @return array<string, ValidationRule|array|string>
*/
public function rules(): array
{
return [
'position' => 'int|max:255',
'name' => 'required|string|max:255|unique:educational_institutions,name',
'description' => 'string',
'name' => [
'required',
'string',
'max:255',
"unique:educational_institutions,name,{$this->educational_institution->id}",
],
];
}
}

View File

@ -5,7 +5,7 @@
<div class="row">
<div class="col">
<h1 class="">Изменить учебное заведение</h1>
{{ Form::open(['url' => route('educational-institutions.update', $educationalInstitution), 'method' => 'PATCH', 'class' => '']) }}
{{ Form::model($educationalInstitution, ['route' => ['educational-institutions.update', $educationalInstitution], 'method' => 'PATCH', 'class' => '']) }}
<div class="col">
<div>
{{ Form::label('position', 'Позиция') }}

View File

@ -21,9 +21,9 @@
@foreach($educationalInstitutions as $educationalInstitution)
<tr class="">
<th scope="row">{{ $educationalInstitution->position }}</th>
<td>{{ $educationalInstitution->name }}</td>
<td>{{ $educationalInstitution->description }}</td>
<td><a href="{{ route("educational-institutions.edit", $educationalInstitution) }}"
<td><a href="{{ route('educational-institutions.show', $educationalInstitution) }}">{{ $educationalInstitution->name }}</a></td>
<td>{{ Str::words($educationalInstitution->description, 10, '...') }}</td>
<td class="col-3"><a href="{{ route("educational-institutions.edit", $educationalInstitution) }}"
class="btn btn-secondary">редактировать</a>
<a rel="nofollow" data-method="delete" data-confirm="Вы действительно хотите удалить?"
href="{{ route('educational-institutions.destroy', $educationalInstitution) }}"

View File

@ -0,0 +1,18 @@
@extends('layouts.admin-layout')
@section('content')
@auth()
<div class="container mt-4">
<h2>Название</h2>
<p>{{ $educationalInstitution->name }}</p>
<h2>Описание</h2>
<p>{{ $educationalInstitution->description }}</p>
<h2>Позиция</h2>
<p>{{ $educationalInstitution->position }}</p>
<h2>Факультеты</h2>
@foreach($educationalInstitution->faculties as $faculty)
<p><a href="{{ route('faculties.show', $faculty) }}">{{ $faculty->name }}</a></p>
@endforeach
</div>
@endauth
@endsection