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

iamlux20's avatar

Exclude null contents into Request

I'm trying to do a table where there's a checkbox and a quantity count (if checked), and null contents are being sent. Is there a way to exclude that?

For reference:

<td>
    <label class="checkbox deliveryNotesLabel">
    <input type="checkbox" class="deliveryNotes" name="deliveryNotes[]" value="{{ $item->id }}"/>
        <span></span>
    </label>
</td>
<td>
    <input type="number" min="0" max="100" name="vans[]" class="form-control">
</td>

this is what $request->all() retrieves when I try to pick 2nd and 3rd items:

array:3 [▼
  "_token" => "DzGh2Q7fjhfbr4iexJ1c4AaTd8QlrA60zBphMgV7"
  "vans" => array:4 [▼
    0 => null
    1 => "1"
    2 => "2"
    3 => null
  ]
  "deliveryNotes" => array:2 [▼
    0 => "8"
    1 => "7"
  ]
]
0 likes
2 replies
Tray2's avatar

Since you are using the array syntax in your form and an empty checkbox is null you will have to handle that in your controller. You can of course handle it with javascript but you still have to handle it in the controller.

Please or to participate in this conversation.