【发布时间】:2021-09-27 18:23:24
【问题描述】:
如果密码不符合规则,我想更改消息的语言。
我使用以下代码检查密码:
'password' => ['required', 'confirmed', Password::min(12)
->mixedCase()
->letters()
->numbers()
->symbols()
->uncompromised()
],
如果密码不符合规则,我会收到一条错误消息,但为英文。我想用德语收到这个。我找到了生成消息的方法。在那里,它们是用英语静态编程的。我该如何更改?
public function passes($attribute, $value)
{
$validator = Validator::make($this->data, [
$attribute => 'string|min:'.$this->min,
]);
if ($validator->fails()) {
return $this->fail($validator->messages()->all());
}
$value = (string) $value;
if ($this->mixedCase && ! preg_match('/(\p{Ll}+.*\p{Lu})|(\p{Lu}+.*\p{Ll})/u', $value)) {
$this->fail('The :attribute must contain at least one uppercase and one lowercase letter.');
}
if ($this->letters && ! preg_match('/\pL/u', $value)) {
$this->fail('The :attribute must contain at least one letter.');
}
if ($this->symbols && ! preg_match('/\p{Z}|\p{S}|\p{P}/u', $value)) {
$this->fail('The :attribute must contain at least one symbol.');
}
if ($this->numbers && ! preg_match('/\pN/u', $value)) {
$this->fail('The :attribute must contain at least one number.');
}
if (! empty($this->messages)) {
return false;
}
if ($this->uncompromised && ! Container::getInstance()->make(UncompromisedVerifier::class)->verify([
'value' => $value,
'threshold' => $this->compromisedThreshold,
])) {
return $this->fail(
'The given :attribute has appeared in a data leak. Please choose a different :attribute.'
);
}
return true;
}
当我尝试更改代码时,PHP-Storm 会警告我不要这样做。有人有建议吗?
【问题讨论】:
-
永远不要覆盖供应商文件夹中的任何内容。阅读this link on localizing the language
-
@aynber 这些消息未在 lang 文件夹的 validation.php 中定义
-
没人知道???
标签: php laravel translation