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

skylar01128's avatar

Querying from an array

I have an array that is stemming from the selection of multiple check boxes by the name of "select[]". Each check box relates to a menu item stored in the database. The value of the checkbox is the id that corresponds to that menu item. So when the user checks those boxes, an array is built containing the IDs of the items that they checked.

This is working just fine and I'm able to dd all of the input selections and view the JSON (which is just an array of the item ids), no problems there.

    $selected = request()->input('select');
    dd($selected); 

However, I now need to iterate through that array so I can query the database for each of the IDs and present each of those items on the next page.

Can anyone help me with that last step?

The model I'm using is called menu and I have been querying using the convention below.

App\model::all();
0 likes
3 replies
skylar01128's avatar

When I selected 4, this is what the dd() displayed:

array:5 [▼ 1 => "6" 2 => "7" 3 => "8" 4 => "9" ]

skylar01128's avatar

The whereIn() method worked just how I needed. Thank you so much for the help!

1 like

Please or to participate in this conversation.