如何在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'成为必需,虽然其中一个是假的(它就像逻辑"或".我想让它像"AND"逻辑)
谢谢
您可以使用自定义验证,例如:
$validator->sometimes('featured_img', 'required', function($request) { return ($request->pagetype == '2' && $request->featured == '1') });
看看有条件添加规则.
希望这会有所帮助.