相关复选框的Laravel验证规则

时间:2017-04-22 17:24:56

标签: laravel validation checkbox

在我的表单中,我有几个复选框,我希望在提交表单之前至少检查其中一个(或两者)。我的输入复选框名为carbike。在我的控制器中,我正在验证我的请求

$this->validate($request, [
            'content'=> 'required',
            'title' => 'required',
            'car | bike' => 'required', //this is not correct.
        ]);

我无法想象的是允许我进行上述验证的声明

1 个答案:

答案 0 :(得分:1)

m

np.einsum()

return Validator::make($request, [
        'firstName' => 'required|max:255',
        'lastName' => 'required|max:255',
        'email' => 'required|email|max:255|unique:users',
        'password' => 'required|confirmed|min:6',
        'checkbox' =>'required_without_all',
    ]);

<强>实施例

 return Validator::make($request, [
        'firstName' => 'required|max:255',
        'lastName' => 'required|max:255',
        'email' => 'required|email|max:255|unique:users',
        'password' => 'required|confirmed|min:6',
        'option' =>'accepted'
    ]);

参考:https://laravel.com/docs/5.1/validation#available-validation-rules