如何添加laravel multiple required_if(如AND Logical)

时间:2016-01-02 09:25:11

标签: php laravel-5.1

如何在Laravel验证中添加laravel multiple required_if(如AND Logical)。我想要'featured_img' if (pagetype == '2' and featured == '1')

我试试这个:

'featured_img'   => 'required_if:pagetype,2|required_if:featured,1|mimes:jpg,jpeg,bmp,png',

但是这个验证需要'featured_img',但其中一个是假的(它就像逻辑“OR”。我想让它像“AND”逻辑)

由于

1 个答案:

答案 0 :(得分:5)

您可以使用自定义验证,如:

$validator->sometimes('featured_img', 'required', function($request) {
    return ($request->pagetype == '2' && $request->featured == '1')
});

查看 Conditionally Adding Rules

希望这会有所帮助。