tenz tenz - 2 years ago 116
PHP Question

How do I data bind to a checkbox input Laravel?

Using Laravel 5.1

I have a form that I am data binding to. Everything work as expected except for the checkbox.

Here is my input (blade template);

<input type="checkbox" name="noContact" value="{{ $profile['noContact'] }}">

The field is a boolean and the checked value should be 1. Doesn't seem to be binding. What am I missing?


Answer Source

Maybe try to use checked="checked" instead of value attribute :

<input type="checkbox" name="noContact"{{ $profile['noContact'] ? ' checked="checked"' : '' }}>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download