There is a table:

filters_to_products Структура: id category_id product_id filter_id 

There is a form

 <form method="get"> <input type="checkbox" value="1" name="array[]"> <input type="checkbox" value="2" name="array[]"> <input type="checkbox" value="3" name="array[]"> <input type="checkbox" value="4" name="array[]"> <button>Filter</button> </form> 

PS Inputs dynamic.

There is a controller:

  foreach($request->input('array') as $row) { $ids = $row; } $items = Item::where('category_id', '1')->whereIn('id', $ids)->get()->all(); 

The trouble is that the filter should filter out the values, for example, if I selected the чекбокс с value 1 и чекбокс с value 2 then I should get only those items that are in the table by coincidence, but it turns out that I have a selection on which have such an id, that is, roughly speaking, positions are not filtered, but are summarized on the basis of filters.

    2 answers 2

    Do you need a where () function?
    Items::where(cpu, 'i7')->where(diagonal, 13)->where(category, 'Notebook')->get();

    UPD

    Then so

      $items = Item::where('category_id', '1') foreach($request->input('array') as $row) { $items->where('id', row) } $items->get(); 

    It should work based on the features of Eloquent, when the request does not end until get() executed. Well, or you can do less perversely through whereRaw, whatever you like.

    • Almost updated the question. - asd

    The easiest way to do it right away is:

     $item = Item::where('category_id', '1')->whereIn('id', array_filter(request()->array))->get();