title: Laravel eloquent model - get rows using intermediate table
body: <p>I have 3 tables users, posts and photos. </p>
  
  <p>post table has one - one relation to photos &amp; users like, <code>post.user_id=users.id</code> and <code>post_photo_id=photos._id</code>.</p>
  
  <p>I use</p>
  
  <pre><code>public function posts(){
      return $this-&gt;hasMany('Post');
  }
  </code></pre>
  
  <p>and I get all the posts by user using $user->posts().</p>
  
  <p>What I need is to get all the photos by user, something like $user->photos.</p>
  
  <p><code>SELECT photos.* 
  FROM photos 
  JOIN posts ON posts.photo_id=photos.id 
  JOIN users ON users.id=posts.user_id 
  WHERE user_id=1</code></p>
  
  <p>Note: photos table has just 2 fields, id &amp; photo.</p>