title: How to filter child table selected using with clause in laravel
body: <p>I am querying Item using following:</p>
  <pre><code>$itemdata = Item::with('itemimagedetails')
      -&gt;with('variation')
      -&gt;select('item.id', 'item.cat_id', 'item.item_name', 'item.item_description', 'item.brand', 'item.manufacturer', 'item.country_origin', 'item.ingredient_type', 'item.delivery_time', 'categories.category_name', 'item.category_unit')
      -&gt;join('categories','item.cat_id','=','categories.id')
      -&gt;where('item.id', $request['item_id'])-&gt;get()-&gt;first();
  </code></pre>
  <p>I want to filter variations using planid fetched from user table.</p>
  <pre><code>$plan = User::where('id', $request['user_id'])
  </code></pre>
  <p>I have tried:</p>
  <pre><code>if (count($itemdata-&gt;variation) &gt; 0) {
      $plan = User::where('id', $request['user_id'])-&gt;get();
  
      foreach ($itemdata-&gt;variation as $key =&gt; $tag_name) {
          if($tag_name == $plan['plan_id']) {
              unset($itemdata-&gt;variation[$key]);
          }
      }
  }
  </code></pre>
  <p>But then I get an error in the API calls.</p>
  <p>Can someone please suggest best approach?</p>