title: Joining an additional table with belongsToMany()?
body: <p>This question is best illustrated by an example:</p>
  
  <pre><code>users
      id
      name
  
  roles
      id
      name
  
  role_user
      user_id
      role_id
      rank_id
      group_id
      ...
  
  ranks
      id
      name
  
  groups
      id
      name
  </code></pre>
  
  <p>I can easily eager load a users table by specifying the following relationship in my <code>User.php</code> model:</p>
  
  <pre><code>public function roles() {
    return $this-&gt;belongsToMany('Role');
  }
  </code></pre>
  
  <p>Which will output the table below when calling <code>User::with('roles')</code>:</p>
  
  <pre><code>User | Role
  -------------
  Jon  | Admin
  Jan  | Mod
  </code></pre>
  
  <p>However I have no idea how to extend this to include:</p>
  
  <pre><code>User | Role  | Rank   | Group
  -----------------------------
  Jon  | Admin | Boss   | Blue 
  Jan  | Mod   | Minion | Red
  </code></pre>
  
  <p>What I've tried doing <code>User::with('roles', 'ranks', 'groups')</code> but that is certainly wrong since I'm telling Laravel there are <code>rank_user</code> and <code>group_user</code> intermediate tables too but there aren't. What is the correct way?</p>
  
  <p>PS: I know it's better to separate the ranks and groups into their own relationship/pivot tables, this is simply an example.</p>
  
  <p>EDIT: Closest example I can find for this: <a href="https://github.com/laravel/framework/issues/2619#issuecomment-38015154" rel="nofollow">https://github.com/laravel/framework/issues/2619#issuecomment-38015154</a></p>