Search code examples
phpcheckboxlaravel-5.4laravel-bladelaravelcollective

Laravel Collective Form checkbox always checked


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.


Solution

  • 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) !!}