使用自定义错误消息的 required_with 没有效果 
                            
                                                    
                        
                    
                    
  
                    
                    PHP代码
Validator::make(
    [
        "title" => [1 => "1", 2 => null],
        "body" => [1 => null,2 => "<p>2</p>"],
    ],
    [
        "title.1" => "required_with:body.1|nullable|string|max:255",
        "body.1" => "required_with:title.1|nullable|string",
        "title.2" => "required_with:body.2|nullable|string|max:255",
        "body.2" => "required_with:title.2|nullable|string",
    ],
    [
        "title.1.required_with:body.1" => "The 中文 (简体) title is required when content 中文 (简体) is present.",
        "body.1.required_with:title.1" => "The 中文 (简体) content is required when title 中文 (简体) is present.",
        "title.2.required_with:body.2" => "The 中文 (繁體) title is required when content 中文 (繁體) is present.",
        "body.2.required_with:title.2" => "The 中文 (繁體) content is required when title 中文 (繁體) is present.",
    ]
);验证结果得到
The body.1 field is required when title.1 is present.The title.2 field is required when body.2 is present.
而不是
The 中文 (简体) content is required when title 中文 (简体) is present.The 中文 (繁體) title is required when content 中文 (繁體) is present.
然后我在 Illuminate\Validation\Concerns\FormatsMessages 的 getFromLocalArray() 发现
"getFromLocalArray -> $keys"
array:2 [▼
  0 => "body.1.required_with"
  1 => "required_with"
]
"getFromLocalArray -> $this->customMessages"
array:4 [▼
  "title.1.required_with:body.1" => "The 中文 (简体) title is required when content 中文 (简体) is present."
  "body.1.required_with:title.1" => "The 中文 (简体) content is required when title 中文 (简体) is present."
  "title.2.required_with:body.2" => "The 中文 (繁體) title is required when content 中文 (繁體) is present."
  "body.2.required_with:title.2" => "The 中文 (繁體) content is required when title 中文 (繁體) is present."
]keys 和 customMessages 的键名对不上,请问我的自定义验证规则有什么写错了吗?
 
           
         
                     
                     
             
           
           关于 LearnKu
                关于 LearnKu
               
                     
                     
                     粤公网安备 44030502004330号
 粤公网安备 44030502004330号 
 
推荐文章: