title: Laravel join with 3 Tables
body: <p>I am building a Twitter-like app. There is a Feed in which I want to only show posts of Users who I follow.</p>
  
  <p>I tried everything with joins, but nothing seems to work.</p>
  
  <p>I have 3 tables: <code>Users</code>, <code>Followers</code>, <code>Shares</code></p>
  
  <p>The Tables look like this:</p>
  
  <p><strong>Users</strong>: <code>id</code></p>
  
  <p><strong>Followers</strong>: <code>user_id</code>, <code>follower_id</code></p>
  
  <p><strong>Shares</strong>: <code>user_id</code></p>
  
  <p>What I need to get is "ALL Shares WHERE share.user_id = followers.follower_id"
  "ANDWHERE followers.user_id = users.id"</p>
  
  <p>Assume, the users.id is 3, I tried this:</p>
  
  <pre><code>$shares = DB::table('shares')
          -&gt;leftjoin('followers', 'shares.user_id', '=', 'followers.follower_id')
          -&gt;leftjoin('users', 'followers.user_id', '=', 'users.id')
          -&gt;where('users.id', 3)
          -&gt;where('shares.user_id', 'followers.follower_id')
          -&gt;get();
  </code></pre>
  
  <p>But it doesnt work.</p>
  
  <p>Any help is appreciated :)</p>