title: User Follow/Subscription Relationship Model In Laravel
body: <p>I am trying to create a youtube style subscription model for my application. I've had small amounts of success so far, that being that you can follow other users and it stores who is following who in the database. However I am having trouble retrieving the list of people the current user is following.</p>
  
  <p>The database:</p>
  
  <p>users table (id, first_name, last_name, email, password, token, timestamps)</p>
  
  <p>subscriptions Table (id, user_id, subscriber_id, timestamps)</p>
  
  <p>user model:</p>
  
  <pre><code>public function subscriptions()
  {
   return $this-&gt;belongsToMany('App\User', 'subscriptions', 'user_id',     
   'subscriber_id')-&gt;withTimestamps();
  }
  
  public function subscribers()
  {
  return $this-&gt;belongsToMany('App\User', 'subscriptions', 'subscriber_id', 
  'user_id')-&gt;withTimestamps();
  }
  </code></pre>
  
  <p>I am using this code to retrieve all of the current users subscriptions (aka who they are following)</p>
  
  <pre><code> $subscriber = Auth::user()-&gt;id;
  
  
   $user = User::find($subscriber);
  
  
   $userids = $user-&gt;subscriptions-&gt;lists('user_id');
  
   return $userids;
  </code></pre>
  
  <p>Now, this code is currently returning a null value. On further investigation this makes sense as the query that is being run is incorrect</p>
  
  <p>SQL Query:</p>
  
  <pre><code>select `user_id` from `users` inner join `subscriptions` on `users`.`id` = `subscriptions`.`subscriber_id` where `subscriptions`.`user_id` = 14
  </code></pre>
  
  <p>My current set up is trying to look for the wrong thing.</p>
  
  <p>If user 1 follows users 2, 3 and 4 then my code should return 2, 3 and 4.</p>
  
  <p>Can somebody please help correct my relationship set up or the code that I am running? It should be looking for the user_id in the subscriptions table based on the current users subscriber_ID.</p>