title: Laravel pivot: Get model from withPivot()
body: <p>I'm building an application using Laravel 4 but have stumbled across a problem with the pivot tables.</p>
  
  <p>I've got a user model, an establishment model, &amp; a studyLevel model.</p>
  
  <p>For the moment to find the establishment a user has been at I use the following code in my User model:</p>
  
  <pre><code>public function establishments()
  {
      return $this-&gt;belongsToMany('Establishment')-&gt;withPivot('start', 'stop', 'study_level_id')-&gt;withTimestamps();
  }
  </code></pre>
  
  <p>The establishment_user (pivot) table has the following columns:</p>
  
  <pre><code>id | establishment_id | user_id | start | stop | study_level_id
  </code></pre>
  
  <p>To get the list of establishments for a user I use the following in a controller:</p>
  
  <pre><code>$establishments = $user_repo-&gt;find($user_id)
                  -&gt;with(['establishments', 'establishments.userSubjects' =&gt; function ($query) use ($user)
                  {
                      $query-&gt;where('user_id', $user-&gt;id);
                  }])
                  -&gt;get();
  </code></pre>
  
  <p>My problem is that the response gives me the ID of the studyLevel but I would like to have the information from the studyLevel model. Is it possible to get information from the studyLevel table using withPivot() ?</p>
  
  <p>Thanks in advance, all help is appreciated.</p>