From 23033cbb1faf668c141270760dcc2e76a006f885 Mon Sep 17 00:00:00 2001 From: aslan Date: Thu, 15 Feb 2024 14:46:35 +0300 Subject: [PATCH] refactoring fix unique field slug in Requests --- app/Http/Requests/admin/Catalog/StoreDepartmentRequest.php | 2 +- app/Http/Requests/admin/Catalog/StoreDirectionRequest.php | 2 +- .../Requests/admin/Catalog/StoreEducationFormRequest.php | 2 +- .../Requests/admin/Catalog/StoreEducationLevelRequest.php | 2 +- .../admin/Catalog/StoreEducationalInstitutionRequest.php | 2 +- app/Http/Requests/admin/Catalog/StoreFacultyRequest.php | 2 +- .../Requests/admin/Catalog/UpdateDepartmentRequest.php | 7 ++++++- app/Http/Requests/admin/Catalog/UpdateDirectionRequest.php | 7 ++++++- .../Requests/admin/Catalog/UpdateEducationFormRequest.php | 2 +- .../Requests/admin/Catalog/UpdateEducationLevelRequest.php | 2 +- .../admin/Catalog/UpdateEducationalInstitutionRequest.php | 7 ++++++- app/Http/Requests/admin/Catalog/UpdateFacultyRequest.php | 7 ++++++- 12 files changed, 32 insertions(+), 12 deletions(-) diff --git a/app/Http/Requests/admin/Catalog/StoreDepartmentRequest.php b/app/Http/Requests/admin/Catalog/StoreDepartmentRequest.php index 929185b..7d0d7f7 100644 --- a/app/Http/Requests/admin/Catalog/StoreDepartmentRequest.php +++ b/app/Http/Requests/admin/Catalog/StoreDepartmentRequest.php @@ -18,7 +18,7 @@ class StoreDepartmentRequest extends FormRequest 'position' => 'required|int|numeric|max:255', 'name' => 'required|string|max:255|unique:departments,name', 'description' => 'string', - 'slug' => 'required|string|max:255', + 'slug' => 'required|string|max:255|unique:departments,slug', 'faculty_id' => 'required|numeric|int|max:1000', ]; } diff --git a/app/Http/Requests/admin/Catalog/StoreDirectionRequest.php b/app/Http/Requests/admin/Catalog/StoreDirectionRequest.php index d5f190f..b78c4e5 100644 --- a/app/Http/Requests/admin/Catalog/StoreDirectionRequest.php +++ b/app/Http/Requests/admin/Catalog/StoreDirectionRequest.php @@ -17,7 +17,7 @@ class StoreDirectionRequest extends FormRequest 'position' => 'required|int|numeric|max:255', 'name' => 'required|string|max:255|unique:directions,name', 'description' => 'string', - 'slug' => 'required|string|max:255', + 'slug' => 'required|string|max:255|unique:directions,slug', 'code' => 'required|string|max:255', 'education_level_id' => 'required|int|numeric|max:1000', 'education_form_id' => 'required|int|numeric|max:1000', diff --git a/app/Http/Requests/admin/Catalog/StoreEducationFormRequest.php b/app/Http/Requests/admin/Catalog/StoreEducationFormRequest.php index d5a553f..cfa577f 100644 --- a/app/Http/Requests/admin/Catalog/StoreEducationFormRequest.php +++ b/app/Http/Requests/admin/Catalog/StoreEducationFormRequest.php @@ -16,7 +16,7 @@ class StoreEducationFormRequest extends FormRequest return [ 'name' => 'required|string|max:255|unique:education_levels,name', 'description' => 'string', - 'slug' => 'required|string|max:255', + 'slug' => 'required|string|max:255|unique:education_levels,slug', ]; } } diff --git a/app/Http/Requests/admin/Catalog/StoreEducationLevelRequest.php b/app/Http/Requests/admin/Catalog/StoreEducationLevelRequest.php index 0abf0ad..4ee733e 100644 --- a/app/Http/Requests/admin/Catalog/StoreEducationLevelRequest.php +++ b/app/Http/Requests/admin/Catalog/StoreEducationLevelRequest.php @@ -16,7 +16,7 @@ class StoreEducationLevelRequest extends FormRequest return [ 'name' => 'required|string|max:255|unique:education_levels,name', 'description' => 'string', - 'slug' => 'required|string|max:255', + 'slug' => 'required|string|max:255|unique:education_levels,slug', ]; } } diff --git a/app/Http/Requests/admin/Catalog/StoreEducationalInstitutionRequest.php b/app/Http/Requests/admin/Catalog/StoreEducationalInstitutionRequest.php index 5f91850..af506f6 100644 --- a/app/Http/Requests/admin/Catalog/StoreEducationalInstitutionRequest.php +++ b/app/Http/Requests/admin/Catalog/StoreEducationalInstitutionRequest.php @@ -17,7 +17,7 @@ class StoreEducationalInstitutionRequest extends FormRequest 'position' => 'required|int|numeric|max:255', 'name' => 'required|string|max:255|unique:educational_institutions,name', 'description' => 'string', - 'slug' => 'required|string|max:255', + 'slug' => 'required|string|max:255|unique:educational_institutions,slug', ]; } } diff --git a/app/Http/Requests/admin/Catalog/StoreFacultyRequest.php b/app/Http/Requests/admin/Catalog/StoreFacultyRequest.php index a025af7..a5789a1 100644 --- a/app/Http/Requests/admin/Catalog/StoreFacultyRequest.php +++ b/app/Http/Requests/admin/Catalog/StoreFacultyRequest.php @@ -18,7 +18,7 @@ class StoreFacultyRequest extends FormRequest 'position' => 'required|int|numeric|max:255', 'name' => 'required|string|max:255|unique:faculties,name', 'description' => 'string', - 'slug' => 'required|string|max:255', + 'slug' => 'required|string|max:255|unique:faculties,slug', 'educational_institution_id' => 'required|int|numeric|max:1000' ]; } diff --git a/app/Http/Requests/admin/Catalog/UpdateDepartmentRequest.php b/app/Http/Requests/admin/Catalog/UpdateDepartmentRequest.php index 858fac1..f230924 100644 --- a/app/Http/Requests/admin/Catalog/UpdateDepartmentRequest.php +++ b/app/Http/Requests/admin/Catalog/UpdateDepartmentRequest.php @@ -15,7 +15,12 @@ class UpdateDepartmentRequest extends FormRequest return [ 'position' => 'required|int|numeric|max:255', 'description' => 'string', - 'slug' => 'string|required|max:255', + 'slug' => [ + 'string', + 'required', + 'max:255', + "unique:departments,slug,{$this->department->id}", + ], 'faculty_id' => 'int|required|numeric|max:255', 'name' => [ 'required', diff --git a/app/Http/Requests/admin/Catalog/UpdateDirectionRequest.php b/app/Http/Requests/admin/Catalog/UpdateDirectionRequest.php index c8f4bd5..d9e862b 100644 --- a/app/Http/Requests/admin/Catalog/UpdateDirectionRequest.php +++ b/app/Http/Requests/admin/Catalog/UpdateDirectionRequest.php @@ -18,7 +18,12 @@ class UpdateDirectionRequest extends FormRequest 'position' => 'required||numeric|int|max:255', 'description' => 'string', 'department_id' => 'int|required|numeric|max:1000', - 'slug' => 'required|string|max:255', + 'slug' => [ + 'required', + 'string', + 'max:255', + "unique:directions,slug,{$this->direction->id}", + ], 'code' => 'required|string|max:255', 'education_level_id' => 'required|int|numeric|max:1000', 'education_form_id' => 'required|int|numeric|max:1000', diff --git a/app/Http/Requests/admin/Catalog/UpdateEducationFormRequest.php b/app/Http/Requests/admin/Catalog/UpdateEducationFormRequest.php index 61a2092..f681d9b 100644 --- a/app/Http/Requests/admin/Catalog/UpdateEducationFormRequest.php +++ b/app/Http/Requests/admin/Catalog/UpdateEducationFormRequest.php @@ -16,7 +16,7 @@ class UpdateEducationFormRequest extends FormRequest return [ 'name' => "required|string|max:255|unique:education_forms,name,{$this->education_form->id}", 'description' => 'string', - 'slug' => 'required|string|max:255', + 'slug' => "required|string|max:255|unique:education_forms,slug,{$this->education_form->id}", ]; } } diff --git a/app/Http/Requests/admin/Catalog/UpdateEducationLevelRequest.php b/app/Http/Requests/admin/Catalog/UpdateEducationLevelRequest.php index 196568d..c2e5a27 100644 --- a/app/Http/Requests/admin/Catalog/UpdateEducationLevelRequest.php +++ b/app/Http/Requests/admin/Catalog/UpdateEducationLevelRequest.php @@ -16,7 +16,7 @@ class UpdateEducationLevelRequest extends FormRequest return [ 'name' => "required|string|max:255|unique:education_levels,name,{$this->education_level->id}", 'description' => 'string', - 'slug' => 'required|string|max:255', + 'slug' => "required|string|max:255|unique:education_levels,slug,{$this->education_level->id}", ]; } } diff --git a/app/Http/Requests/admin/Catalog/UpdateEducationalInstitutionRequest.php b/app/Http/Requests/admin/Catalog/UpdateEducationalInstitutionRequest.php index 670cb9b..0111f53 100644 --- a/app/Http/Requests/admin/Catalog/UpdateEducationalInstitutionRequest.php +++ b/app/Http/Requests/admin/Catalog/UpdateEducationalInstitutionRequest.php @@ -17,7 +17,12 @@ class UpdateEducationalInstitutionRequest extends FormRequest return [ 'position' => 'required|int|numeric|max:255', 'description' => 'string', - 'slug' => 'required|string|max:255', + 'slug' => [ + 'required', + 'string', + 'max:255', + "unique:educational_institutions,slug,{$this->educational_institution->id}", + ], 'name' => [ 'required', 'string', diff --git a/app/Http/Requests/admin/Catalog/UpdateFacultyRequest.php b/app/Http/Requests/admin/Catalog/UpdateFacultyRequest.php index f525256..b045a17 100644 --- a/app/Http/Requests/admin/Catalog/UpdateFacultyRequest.php +++ b/app/Http/Requests/admin/Catalog/UpdateFacultyRequest.php @@ -16,7 +16,12 @@ class UpdateFacultyRequest extends FormRequest return [ 'position' => 'required|int|numeric|max:255', 'description' => 'string', - 'slug' => 'required|string|max:255', + 'slug' => [ + 'required', + 'string', + 'max:255', + "unique:faculties,slug,{$this->faculty->id}", + ], 'educational_institution_id' => 'required|int|numeric|max:255', 'name' => [ 'required',