Laravel 4, how to test if a Checkbox is checked?

checkbox, laravel, laravel-4, php

Solution

Assuming you have this form code in your view:

// view.blade.php
{{ Form::open() }}
    {{ Form::checkbox('attending_lan', 'yes') }}
    {{ Form::submit('Send') }}
{{ Form::close() }}

You can get the value of the checkbox like this:

if (Input::get('attending_lan') === 'yes') {
    // checked
} else {
    // unchecked
}

The key here is that you have to set a value when creating the checkbox in your view (in the example, value would be `yes`), and then check for that value in your controller.

Problem

I am trying to see if a checkbox is checked or not in my controller. I've read that this is the code to do it ``` if (Input::get('attending_lan', true)) ``` But that returns true even if the checkbox is unchecked.

Original source

Related problems