Laravel validation checkbox Laravel validation checkbox php php

Laravel validation checkbox


Use the accepted rule.

The field under validation must be yes, on, 1, or true. This is useful for validating "Terms of Service" acceptance.

Sample for your case:

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


It will work, just be sure the input value will not be an empty string or false. And 'checkbox' =>'required' is ok as long as the key is the value of the input name attribute.


Use required_without_all for checkbox :

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

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