title: Laravel 5.5 User model and friends relationship (belongsToMany) by multiple columns
body: <h1>Problem</h1>
  
  <p>I created a simple friendship relationship for my Laravel app which all worked ok until I noticed that when I queried the friendship of a user it would only search the current user on the <code>UID1</code> field.</p>
  
  <p>Since friendships are in essence a two-way relationship, Im trying to find a way in a laravel Model to retrieve ALL friendships relations by multiple columns.</p>
  
  <h2>Current Implementation</h2>
  
  <pre><code>    public function friends()
      {
          return $this-&gt;belongsToMany( App\Modules\Users\Models\User::class ,'friends', 'uid1');
      }
  </code></pre>
  
  <h2>Ideal Implementation</h2>
  
  <pre><code>    public function friends()
      {
          $a = $this-&gt;belongsToMany( App\Modules\Users\Models\User::class ,'users_friends', 'uid1');
          $b = $this-&gt;belongsToMany( App\Modules\Users\Models\User::class ,'users_friends', 'uid2');
  
          return combine($a,$b);
  
      }
  </code></pre>
  
  <h2>Table Structure</h2>
  
  <pre><code>     +----------------------+
       | users table          |
       +----------------------+
  +----|   id: primary UserID |
  |    |   fname: string      |
  |    +----------------------+
  |    
  |    
  |    +----------------------+
  |    | friends table        |
  |    +----------------------+
  |    |   id: primary iD     |
  |    |                      |
  +----|   uid1: user_id      |
  |    |                      |
  +----|   uid2: user_id      |
       +----------------------+
  </code></pre>
  
  <p>The current implementation will only result in 1 of these records returning if the Current UserID = 1 as per the data in the friends table below.</p>
  
  <pre><code>     +-------------------------------+
       |      friends table (data)     |
       +--------|---------|------------+
       |   id   |  uid1   |   uid2     |
       +--------|---------|------------+
       |    1   |   1     |    7       |
       |    2   |   7     |    1       |
       |    3   |   9     |    1       |
       +-------------------------------+      
  </code></pre>
  
  <h2>User Model</h2>
  
  <pre><code>&lt;?php
  
  namespace App\Modules\Users\Models;
  
  use Illuminate\Database\Eloquent\Model;
  
  
  class User extends Model
  {
  
  
      protected $table = 'users';
  
  
      protected $fillable = [
          'username', 'email', 'password', .... . 
      ];
  
  
      public function friends()
      {
          return $this-&gt;belongsToMany( App\Modules\Users\Models\User::class ,'users_friends', 'uid1');
  
      }
  </code></pre>
  
  <h2>Environment</h2>
  
  <ul>
  <li>Server = Homestead/linux</li>
  <li>PHP = 7</li>
  <li>MySQL</li>
  </ul>
  
  <h1>Update</h1>
  
  <p>I have a FriendShip helper class I created which does something similar, however in this function I pass in the UserID explicitly</p>
  
  <pre><code>Friendship::where( [
                      [ 'uid1' ,'=', $uid],
                  ])-&gt;orWhere( [
                      [ 'uid2', '=', $uid]
                  ])-&gt;all();
  </code></pre>