title: Using pivot model data as a relationship to another model in Laravel 4's Eloquent
body: <p>I have a pivot table for a many to many relationship which includes a third index parameter for another model. I would like to be able to use Eloquent to access this model.</p>
  
  <p>In my application, I have a <code>User</code> who can have many <code>Subjects</code> and many <code>Semesters</code>. When a user has a <code>Subject</code>, it needs to belong to a given <code>Semester</code> as well. I have a <code>users</code>, <code>subjects</code> and <code>semesters</code> table, as well as a <code>subject_user</code> table (which has <code>user_id</code>, <code>subject_id</code> and <code>semester_id</code>).</p>
  
  <p>When I retrieve the <code>User</code>'s subjects, I would also like to be able to get the <code>Session</code> the <code>Subject</code> has been connected to through the pivot table.</p>
  
  <pre><code>class User
  {
      public function subjects()
      {
          $this-&gt;belongsToMany('Subject')-&gt;withPivot('session_id');
      }
  }
  </code></pre>
  
  <p>What I would like to be able to do is as follows, and have the <code>Session</code> model available to me.</p>
  
  <pre><code>$user-&gt;subjects()-&gt;pivot-&gt;semester;
  </code></pre>
  
  <p>Is such a thing possible, or will this require an extension to Eloquent?</p>