Chron
2 months ago
174
1
Laravel

checkbox validation

Posted 2 months ago by Chron

I have this:

<input type="checkbox" name="checkbox" id="checkbox" value="1"> Is this true?
$data = $request->validate([
    		'field1' => ['required'],
    		'field2' => ['required'],
            	'checkbox' => ['boolean']
  	     ]);

Model::create([
			'field1' => $data['field1'],
			'field2' => $data['field2'],
			'checkbox' => $data['checkbox'],
]);

Whenever I don't check the box, I get a validation error saying it must be boolean

Please sign in or create an account to participate in this conversation.