diff --git a/phpcs.xml b/phpcs.xml index f7ab15d..2c880af 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -5,6 +5,7 @@ PHPCS ruleset src + src/resources diff --git a/src/Providers/EloquentValidationServiceProvider.php b/src/Providers/EloquentValidationServiceProvider.php index 8bc5f77..2a4dbb2 100644 --- a/src/Providers/EloquentValidationServiceProvider.php +++ b/src/Providers/EloquentValidationServiceProvider.php @@ -30,6 +30,7 @@ public function boot() $this->addArrayKeysOnlyRule(); $this->addNotEmpty(); $this->addIsListRule(); + $this->updateDefaultRules(); // langs $this->loadTranslationsFrom(__DIR__.'/../resources/lang/', 'eloquent-validation'); @@ -185,4 +186,28 @@ private function addIsListRule(): void ); }); } + + /** + * @return void + */ + private function updateDefaultRules(): void + { + \Validator::replacer('max', function ($message, $attribute, $rule, $parameters, $validator) { + $value = $parameters[0]; + if (isset($parameters[1])) { + $value = trans($parameters[1]); + } + + return str_replace(':max', $value, $message); + }); + + \Validator::replacer('min', function ($message, $attribute, $rule, $parameters, $validator) { + $value = $parameters[0]; + if (isset($parameters[1])) { + $value = trans($parameters[1]); + } + + return str_replace(':min', $value, $message); + }); + } }