3

I'm using Laravel Collective for Forms and having an issue with checkbox.

Here is what I'm doing :

{!! Form::checkbox('independent',null,['class'=>'form-control', 'required' => 'required'])!!}

I've tried changing values for "null", added one more parameters as suggested by many while googling for solution but nothing seems to be working.

If anyone know the solution or having same issue, please share.

Praveen Dabral
  • 2,449
  • 4
  • 32
  • 46

1 Answers1

7

The documentation states that the third parameter is a boolean that determines if the checkbox is checked, you have an array as the third parameter. Php interprets an array as true, this is why your checkbox is always checked.

You should add true or false as the third parameter and add the options array as a fourth parameter. This can be found in the source code on GitHub.

{!! Form::checkbox('independent', null, false) !!}
Jerodev
  • 32,252
  • 11
  • 87
  • 108
  • Already tried this, adding third parameter is converting checkbox to input box. – Praveen Dabral Apr 21 '17 at 08:38
  • What version of the Laravel Collective are you using? – Jerodev Apr 21 '17 at 08:50
  • Laravel Collective 5.3, I've linked it in question. – Praveen Dabral Apr 21 '17 at 08:53
  • Why are you adding these parameters to the checkbox? the bootstrap `form-control` class will change nothing to the appearance of a checkbox because it is impossible to change this. `required` is also irrelevant here because a checkbox is either checked or not, you can't be sure a user changed this. Could you test without the last parameter? I updated my answer this way. – Jerodev Apr 21 '17 at 09:44
  • In case we need to style checkbox then how should we do that? – Praveen Dabral Apr 21 '17 at 10:45
  • You cannot style an `input[type=checkbox]` element, the best way to do this is to hide the checkbox and style the parent div. – Jerodev Apr 21 '17 at 10:48
  • I can see fourth parameter $options which I believe is for class and id. – Praveen Dabral Apr 21 '17 at 10:55