How to handle unchecked checkboxes in Laravel?

Try this

<input type="hidden" name="param" value="0">
<input type="checkbox" name="param" value="1">

if checkbox is checked => server get "1"

otherwise => server get "0"


From mozilla documentation on checkbox:

If a checkbox is unchecked when its form is submitted, there is no value submitted to the server to represent its unchecked state (e.g. value=unchecked); the value is not submitted to the server at all.

So, the following will do the trick:

$isChecked = $request->has('checkbox-name');

Place a hidden textbox with a 0 value before the checkbox so a 0 value is sent into the POST array.

{{Form::hidden('value',0)}}
{{Form::checkbox('value')}}

The best way I can think of is using ternary and null coalesce PHP operators:

$request->checkbox ? 1 : 0 ?? 0;

This will return 1 if checked, 0 if not checked or not available.