title: Laravel - Has many of self through
body: <p>I have two models, <code>User</code> and <code>Appointment</code>. Users can have clients which are also users. These clients are referenced in appointments under <code>client_id</code>:</p>
  
  <p>The appointment table looks like this:</p>
  
  <p><code>Appointment</code></p>
  
  <p><code>id|user_id|client_id</code></p>
  
  <p>I'd like to pull all clients per user (uniques) but having difficulty crafting the relationship (hasManyThrough – User has many Users (clients) through Appointments). </p>
  
  <p>Based on my understanding of the Laravel docs, the following should work:</p>
  
  <pre><code>User.php
  
  public function clients()
  {
      return $this-&gt;hasManyThrough('App\User', 'App\Appointment', 'client_id', 'user_id', 'id');
  }
  </code></pre>
  
  <p>-</p>
  
  <pre><code>Appointment.php
  
  public function user()
  {
      return $this-&gt;belongsTo('App\User');
  }
  
  public function client()
  {
      return $this-&gt;belongsTo('App\User', 'client_id');
  }
  </code></pre>
  
  <p>Alas it does not get me what I'm looking for. Should I craft my own query?</p>