【发布时间】:2021-03-23 19:42:16
【问题描述】:
在我的控制器中,我正在尝试为自定义验证规则自定义错误消息。问题是自定义规则没有名称,因此我在自定义此规则的错误消息时遇到了一些困难。
Controller.php
$request->validate([
"address.house" => ['bail', 'string', 'nullable', 'max:100', new CustomRule]
],
[
"address.house.hereWillBeTheNameOfCustomRule" => "Custom message for custom rule"
]);
CustomRule.php
public function message()
{
return "I want to override this message.";
}
【问题讨论】:
-
告诉我您是否在 CustomRule 类中定义了
message()方法?或者您可以在索引为“custom_rule”的resources/lang/en/validation.php文件中添加消息。 -
我已经定义了消息方法。我想覆盖该消息。