Laravel 5.2 required_without_all请求问题

时间:2016-03-05 13:10:05

标签: validation laravel laravel-5.2

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

对我做错了什么的想法?

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',
    ];
}

1 个答案:

答案 0 :(得分: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',
    ];
}