diff --git a/app/Api/v1/Requests/SettingUpdateRequest.php b/app/Api/v1/Requests/SettingUpdateRequest.php index 4de55917..b5e11d58 100644 --- a/app/Api/v1/Requests/SettingUpdateRequest.php +++ b/app/Api/v1/Requests/SettingUpdateRequest.php @@ -3,6 +3,7 @@ namespace App\Api\v1\Requests; use App\Rules\IsValidEmailList; +use App\Rules\IsValidRegex; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Support\Facades\Auth; @@ -25,14 +26,28 @@ public function authorize() */ public function rules() { - $rule = [ - 'value' => [ - 'required', - ], - ]; + $routeParam = $this->route()?->parameter('settingName'); - if ($this->route()?->parameter('settingName') == 'restrictList') { - $rule['value'][] = new IsValidEmailList; + if ($routeParam == 'restrictList') { + $rule = [ + 'value' => [ + new IsValidEmailList, + ], + ]; + } + else if ($routeParam == 'restrictRule') { + $rule = [ + 'value' => [ + new IsValidRegex, + ], + ]; + } + else { + $rule = [ + 'value' => [ + 'required', + ], + ]; } return $rule; diff --git a/app/Rules/IsValidRegex.php b/app/Rules/IsValidRegex.php new file mode 100644 index 00000000..03112192 --- /dev/null +++ b/app/Rules/IsValidRegex.php @@ -0,0 +1,26 @@ +translate(); + } + } + catch (\Throwable $ex) { + $fail('validation.IsValidRegex')->translate(); + } + } +} diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index b49f6f93..c86ec16f 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -143,6 +143,7 @@ 'single' => 'When using :attribute it must be the only parameter in this request body', 'onlyCustomOtpWithUri' => 'The uri parameter must be provided alone or only in combination with the \'custom_otp\' parameter', + 'IsValidRegex' => 'The :attribute must be a valid regex pattern.', /* |-------------------------------------------------------------------------- @@ -187,7 +188,7 @@ ], 'ids' => [ 'regex' => 'IDs must be comma separated, without trailing comma.', - ] + ], ], /*