How to create a checkbox field in Laravel

Check box allows users to select one or more options from a pre-defined set of values. To create a checkbox field in Laravel you can use the following code. First parameter is the name of the checkbox and second parameter is the value.

{{ Form::checkbox('name', 'value') }}

This will generate following HTML output,

<input name="name" type="checkbox" value="value">

You can pass third argument as true to output a checkbox which is pre-selected.

{{ Form::checkbox('name', 'value', true); }}

This will produce,

<input checked="checked" name="name" type="checkbox" value="value">

Also, you can add HTML attributes to the checkbox.

{{ Form::checkbox('name', 'value', null, array('id'=>'someId')) }}

This will create an Checkbox input field with id attribute.

<input id="someId" name="name" type="checkbox" value="value">

Useful Read : How to Create a Select Box Field in Laravel

0 Comments

Leave a Comment.