我无法为枚举规则添加自定义验证消息。
我的规则定义为:
'components.*.component_type' => ['required', Rule::enum(BlueprintComponentType::class)]
自定义消息定义为:
'custom' => [ 'components.*.component_type' => [ 'enum' => 'The component type field should be ...', ], ],
输出为“The selected Components.0.component_type is invalid”,这是validation.enum的值
尝试使用
in
规则,因为 enum
本质上是 in
规则的简写。
'custom' => [
'components.*.component_type' => [
'in' => 'The component type field should be ...',
],
],
如果上面的代码不起作用,请尝试在 FormRequest 中定义它
public function messages()
{
return [
"components.*.component_type.Illuminate\Validation\Rules\Enum" => "The component type field should be ..."
];
}