title: Laravel 9: items belonging to the same categories
body: <p>I have table of items and table of categories. And I want to get list of items which belong to the same categories. But purly those having the same category. For example:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>ID ITEMS:</th>
  <th>ID CATEGORIES:</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>1</td>
  </tr>
  <tr>
  <td>1</td>
  <td>2</td>
  </tr>
  <tr>
  <td>2</td>
  <td>1</td>
  </tr>
  <tr>
  <td>2</td>
  <td>3</td>
  </tr>
  <tr>
  <td>3</td>
  <td>3</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>If I do this:</p>
  <pre><code>$categoryList = [1, 3];
  $items = Item::with('categories')-&gt;whereHas('categories', function ($q) use ($categoryList) {
          $q-&gt;whereIn('id', $categoryList);
      })-&gt;get();
  
  //-&gt; 1, 2, 3
  </code></pre>
  <p>I get this: ITEM ID = 1, 2, 3.</p>
  <p>But I want to this: <strong>ITEM ID = 2.</strong> Because only item #2 belongs to categories #1 and #3.</p>
  <p>I tried with foreach:</p>
  <pre><code>foreach ($categoryList as $category) {
      $q-&gt;where('id', '=', $category);
  }
  </code></pre>
  <p>But the model give me nothing.</p>
  <p>How to do it? Please help me! </p>
  <pre><code>//In the model item: categories belongsToMany(Item::class)
  //In the model category: items belongsToMany(Category::class)
  </code></pre>