2016-03-05 115 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', 
    ]; 
}