From 36bc47c61cd1a2c462ea62e6d0d87ba643918102 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Tue, 20 Apr 2021 16:44:47 -0500 Subject: [PATCH 1/2] Handle regex format when assigned from API (#9443) --- app/Http/Controllers/Api/CustomFieldsController.php | 9 ++++++++- app/Models/CustomField.php | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Api/CustomFieldsController.php b/app/Http/Controllers/Api/CustomFieldsController.php index 8feb2a116..c42e68b67 100644 --- a/app/Http/Controllers/Api/CustomFieldsController.php +++ b/app/Http/Controllers/Api/CustomFieldsController.php @@ -95,7 +95,14 @@ class CustomFieldsController extends Controller $field = new CustomField; $data = $request->all(); - $validator = Validator::make($data, $field->validationRules()); + $regex_format = null; + + if (str_contains($data["format"], "regex:")){ + $regex_format = $data["format"]; + } + + $validator = Validator::make($data, $field->validationRules($regex_format)); + if ($validator->fails()) { return response()->json(Helper::formatStandardApiResponse('error', null, $validator->errors())); } diff --git a/app/Models/CustomField.php b/app/Models/CustomField.php index 724a323f4..76ae0dd0f 100644 --- a/app/Models/CustomField.php +++ b/app/Models/CustomField.php @@ -353,7 +353,7 @@ class CustomField extends Model * @since [v4.1.10] * @return array */ - public function validationRules() + public function validationRules($regex_format = null) { return [ "name" => "required|unique:custom_fields", @@ -362,7 +362,7 @@ class CustomField extends Model Rule::in(['text', 'listbox', 'textarea', 'checkbox', 'radio']) ], 'format' => [ - Rule::in(array_merge(array_keys(CustomField::PREDEFINED_FORMATS), CustomField::PREDEFINED_FORMATS)) + Rule::in(array_merge(array_keys(CustomField::PREDEFINED_FORMATS), CustomField::PREDEFINED_FORMATS, [$regex_format])) ], 'field_encrypted' => "nullable|boolean" ]; From f3831fe0106a96d8b63c3a640d9b2510da295578 Mon Sep 17 00:00:00 2001 From: Masudul Haque Shihab Date: Wed, 21 Apr 2021 03:49:05 +0600 Subject: [PATCH 2/2] Fixed #9447 change route parameter name in locations view (#9456) --- resources/views/locations/view.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/locations/view.blade.php b/resources/views/locations/view.blade.php index 31e645369..e28908119 100644 --- a/resources/views/locations/view.blade.php +++ b/resources/views/locations/view.blade.php @@ -160,10 +160,10 @@ {{ trans('admin/locations/table.update') }}