title: Laravel Eloquent load relationship inside pivot relationship
body: <p>I'm searching to load a relation inside a pivot table with &quot;-&gt;with()&quot;.</p>
  <p>Table structure: Are 5 tables and Laravel Eloquent models</p>
  <p><strong>user</strong> (id)<br />
  <strong>team</strong> (id)<br />
  <strong>role</strong> (id)<br />
  <strong>team_user</strong> (id, team_id, user_id)<br />
  <strong>team_user_role</strong> (id, team_user_id, role_id)</p>
  <pre><code>class User extends Model {
      function teams(){
          return $this-&gt;belongsToMany(Team::class)
              -&gt;using(TeamUser::class);
      }
  }
  
  class Team extends Model {
      function users(){
          return $this-&gt;belongsToMany(User::class)
              -&gt;using(TeamUser::class);
      }
  }
  
  class TeamUser extends Pivot {
      function roles(){
          return $this-&gt;belongsToMany(Role::class)
              -&gt;using(TeamUserRole::class);
      }
  }
  
  class Role extends Model {}
  class TeamUserRole extends Pivot {}
  </code></pre>
  <p>Ok, I can do that and this works perfectly, the &quot;-&gt;with()&quot; function load roles relationship from TeamUser...</p>
  <pre><code>TeamUser::with('roles')-&gt;first()-&gt;roles // return list of Role::class
  </code></pre>
  <p>...but I need load this &quot;roles&quot; relationship from User::class &quot;User-&gt;teams-&gt;roles&quot;:</p>
  <pre><code>User::with('teams')
      -&gt;with('teams.pivot.roles') // Something like this
      -&gt;first()-&gt;teams-&gt;pivot-&gt;roles; // Expected a list of Role::class
  </code></pre>
  <p>This way a got a RelationNotFoundException, that's make sense because 'pivot' is not a relationship...</p>
  <p>So, in this scenery, how can I access the list of roles from user using QueryBuilder?</p>
  <p>Thanks.</p>
  <p><strong>[Edit]</strong></p>
  <p>I tried:</p>
  <pre><code>User::with('teams.roles') // got a RelationNotFoundException
  </code></pre>