2016-03-05 81 views
1

我遇到问题required_without_all。我有三个元素,至少一个应该填充。我的文件输入名称是image[]。添加一张图片但是仍然保留titlebody仍然会导致验证错误,即使它不应该。Laravel 5.2 required_without_all请求问题

有关我在做什么错的任何想法?

public function rules() 
{ 
    return [ 
     'title' => 'required_without_all:body,image.*', 
     'body' => 'required_without_all:title,image.*', 
     'image.*' => 'required_without_all:body,title', 
    ]; 

} 

public function messages() 
{ 
    return [ 
     'title.required_without_all' => 'At least one field is required', 
     'body.required_without_all'  => 'At least one field is required', 
     'image.*.required_without_all' => 'At least one field is required', 
    ]; 
} 

回答

0

这里已经回答了:https://stackoverflow.com/a/39089295/2101328

基本上,从规则添加image作为数组并取出*

Laravel 5.3还有一个错误,它阻止了类似的工作;看到这个帖子:https://github.com/laravel/framework/issues/15044#issuecomment-244364706

public function rules() 
{ 
    return [ 
     'title' => 'required_without_all:body,image', 
     'body' => 'required_without_all:title,image', 
     'image' => 'array', 
     'image.*' => 'required_without_all:body,title', 
    ]; 
}