Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

pavlen's avatar

Blade check box value

HI, have check box in Blade:

{!! Form::checkbox('reg',1,false) !!}

If box is checed,value is 1,that is ok,but when not checked,value is null.

IS there possibility to send value 0 to conttroller if box is uncheked?

P.S. I can manipulate with values in controller,of course, but just interesting is there away to do that directly in Blade...

Tnx, P

0 likes
4 replies
phildawson's avatar
{!! Form::hidden('reg',0) !!}
{!! Form::checkbox('reg',1,false) !!}
2 likes
pmall's avatar
pmall
Best Answer
Level 56

When a box is not checked, it is not even sent through post data. A cool trick : put a hidden field with the same name before the checkbox.

<input type="hidden" name="reg" value="0">
{!! Form::checkbox('reg',1,false) !!}

So if the form is not checked, the hidden value is sent, if the box is checked it overrides the hidden value.

Otherwise, manage it at controller level :

$value = $request->get('reg', 0); // second parameter is default value
2 likes
bobbybouwmann's avatar

You can check if the variable exists. If not you assign a default value

if (!$request->has('field')) {
    $request->merge(['field' => 0]);
}
3 likes

Please or to participate in this conversation.