title: Query Builder filter for multi level deep relationship in Laravel
body: <p>I have a selection of plots which each belong to a development by a hasManyThrough relationship through housetypes. I want to filter these by development on their overview page. Plots has a housetype_id column and housetypes has a development_id column. </p>
  
  <pre><code>public function plots()
    {
      return $this-&gt;hasManyThrough(Plot::class, Housetype::class);
    }
  </code></pre>
  
  <p>When I use my filter it returns the developments ID number as $development, I then need this to only show plots which are linked to that development.</p>
  
  <p>I have looked into using whereHas or Join methods but have been unable to figure this out. Current filter scope is below. Thanks</p>
  
  <pre><code>public function scopeFilterDevelopment($query)
      {
        $development = request()-&gt;input('filter_development');
  
        if ($development == "") {
          return;
        }
  
        if(!empty($development)){
          $query-&gt;where('development_id', $development);
        }
      }
  </code></pre>