From 941da60c6f7e6511a04a6dda1450c1ff08d14bef Mon Sep 17 00:00:00 2001 From: aslan Date: Wed, 7 Feb 2024 19:27:25 +0300 Subject: [PATCH] refactor educationalInstitution --- app/Http/Controllers/FacultyController.php | 6 +++--- .../UpdateEducationalInstitutionRequest.php | 11 +++++++++-- .../educational-institution/edit.blade.php | 2 +- .../educational-institution/index.blade.php | 6 +++--- .../educational-institution/show.blade.php | 18 ++++++++++++++++++ 5 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 resources/views/catalog/educational-institution/show.blade.php diff --git a/app/Http/Controllers/FacultyController.php b/app/Http/Controllers/FacultyController.php index 43151fb..093c912 100644 --- a/app/Http/Controllers/FacultyController.php +++ b/app/Http/Controllers/FacultyController.php @@ -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'); diff --git a/app/Http/Requests/UpdateEducationalInstitutionRequest.php b/app/Http/Requests/UpdateEducationalInstitutionRequest.php index 0af247b..b89b640 100644 --- a/app/Http/Requests/UpdateEducationalInstitutionRequest.php +++ b/app/Http/Requests/UpdateEducationalInstitutionRequest.php @@ -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> + * @return array */ 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}", + ], ]; } } diff --git a/resources/views/catalog/educational-institution/edit.blade.php b/resources/views/catalog/educational-institution/edit.blade.php index 4aa682b..5e85ac4 100644 --- a/resources/views/catalog/educational-institution/edit.blade.php +++ b/resources/views/catalog/educational-institution/edit.blade.php @@ -5,7 +5,7 @@

Изменить учебное заведение

- {{ Form::open(['url' => route('educational-institutions.update', $educationalInstitution), 'method' => 'PATCH', 'class' => '']) }} + {{ Form::model($educationalInstitution, ['route' => ['educational-institutions.update', $educationalInstitution], 'method' => 'PATCH', 'class' => '']) }}
{{ Form::label('position', 'Позиция') }} diff --git a/resources/views/catalog/educational-institution/index.blade.php b/resources/views/catalog/educational-institution/index.blade.php index 522941c..8906b4e 100644 --- a/resources/views/catalog/educational-institution/index.blade.php +++ b/resources/views/catalog/educational-institution/index.blade.php @@ -21,9 +21,9 @@ @foreach($educationalInstitutions as $educationalInstitution) {{ $educationalInstitution->position }} - {{ $educationalInstitution->name }} - {{ $educationalInstitution->description }} - {{ $educationalInstitution->name }} + {{ Str::words($educationalInstitution->description, 10, '...') }} + редактировать +

Название

+

{{ $educationalInstitution->name }}

+

Описание

+

{{ $educationalInstitution->description }}

+

Позиция

+

{{ $educationalInstitution->position }}

+

Факультеты

+ @foreach($educationalInstitution->faculties as $faculty) +

{{ $faculty->name }}

+ @endforeach +
+ @endauth +@endsection