Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
AnourValar committed Nov 13, 2023
1 parent f2d7766 commit 7691d4f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<description>PHPCS ruleset</description>

<file>src</file>
<exclude-pattern>src/resources</exclude-pattern>

<!-- Show progress of the run -->
<arg value= "p"/>
Expand Down
25 changes: 25 additions & 0 deletions src/Providers/EloquentValidationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function boot()
$this->addArrayKeysOnlyRule();
$this->addNotEmpty();
$this->addIsListRule();
$this->updateDefaultRules();

// langs
$this->loadTranslationsFrom(__DIR__.'/../resources/lang/', 'eloquent-validation');
Expand Down Expand Up @@ -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);
});
}
}

0 comments on commit 7691d4f

Please sign in to comment.