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

FareedR's avatar

How can I take all value in checkbox array ?

I'm getting this error because the value doesnt have default value " Undefined offset : 1 " . How can I take uncheck checkbox value ?

// blade 
<div class="col-3 mt-2">
    <div class="checkbox checkbox-danger-custom">
          <input id="contradict" type="checkbox" name="contradict[]" value="1">
           <label for="contradict">Contradict</label>
     </div>
</div>

// controller
$contradicts    = $request->get('contradict');

        foreach($contradicts as $contradict){
            if(!$request->has('contradict')){
                $request->merge(['contradict' => 0]);
            }

        }

already try this method . still error given . 
0 likes
5 replies
Amaury's avatar
<input type="checkbox" name="option" selected>
request()->has('option') === false // checkbox is unselected

request()->has('option') === true // checkbox is selected
FareedR's avatar

is this valid for array checkbox too ?

Amaury's avatar

If you have an array checkbox, what you have to do is this:

<input type="checkbox" name="contradict[]">
foreach(request()->contradict as $c) {
    // $c is checked ...
}

Only the checked checkboxes are in request()->contradict.

Snapey's avatar

You have multiple checkboxes. What do they relate to? you need to give the checkbox a value unless all you need to know is how many checkboxes are checked, not which ones.

Your code at the moment just keeps overwriting the same value

FareedR's avatar
FareedR
OP
Best Answer
Level 3

im using isset method to solved this .

 'is_contradict' => isset($contradicts[$key]) ? $contradicts[$key] : 0

Please or to participate in this conversation.