title: HasManyThrough with polymorphic and many-to-many relations
body: <p>In my Laravel application I have the following classes:</p>
  
  <pre><code>class Product extends Model
  {
      public function extended()
      {
          return $this-&gt;morphTo();
      }
  
      public function users {
          return $this-&gt;belongsToMany('App\User', 'products_users', 'product_id');
      }
  }
  
  class Foo extends Model 
  {
      public function product()
      {
          return $this-&gt;morphOne('App\Product', 'extended');
      }
      public function bars()
      {
          return $this-&gt;hasMany('App\Bar');
      }
  }
  
  class Bar extends Model 
  {
      public function product()
      {
          return $this-&gt;morphOne('App\Product', 'extended');
      }
  
      public function foo()
      {
          return $this-&gt;belongsTo('App\Foo');
      }
  }
  
  class User extends Model
  {
      public function products()
      {
          return $this-&gt;belongsToMany('App\Product', 'products_users', 'user_id');
      }
  }
  </code></pre>
  
  <p>I can easily get users of a bar object using <code>Bar::find(1)-&gt;product-&gt;users</code> and I can also get the bars of a user with <code>User::find(1)-&gt;products</code>.</p>
  
  <p>How can I get the users of all bars belonging to a specific foo? That is, <code>Foo::find(1)-&gt;users</code> should return all users that have the bars belonging to Foo with id 1. It's basically <a href="https://laravel.com/docs/5.2/eloquent-relationships#has-many-through">hasManyThrough</a> with polymorphic and many-to-many relations.</p>