title: Laravel Multiple linking column in another table with relationships?
body: <p>I'm trying to create a league table in Laravel but I'm running into some issues with guess what, relationships, again. They never seem to work for me in Laravel. It's like they hate me.</p>
  
  <p>I have a modal for matches</p>
  
  <pre><code>&lt;?php
  
  namespace App\Database;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Match extends Model
  {
      protected $primaryKey = 'id';
  
      protected $table = 'matches';
      public $timestamps = false;
      protected $guarded = ['id'];
  }
  </code></pre>
  
  <p>And a modal for teams, but with a matches() function</p>
  
  <pre><code>&lt;?php
  
  namespace App\Database;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Team extends Model
  {
      protected $primaryKey = 'id';
  
      protected $table = 'teams';
      public $timestamps = false;
      protected $guarded = ['id'];
  
      public function matches() {
          return $this-&gt;hasMany('App\Database\Match', 'team_one_id, team_two_id');
      }
  }
  </code></pre>
  
  <p>I think the issue comes with <code>team_one_id, team_two_id</code> as the teams primary key could be in either one of them columns for the other table. When calling <code>count()</code> on <code>matches()</code> it throws an error.</p>
  
  <blockquote>
    <p>SQLSTATE[42S22]: Column not found: 1054 Unknown column 'matches.team_one_id, team_two_id' in 'where clause' (SQL: select count(*) as aggregate from <code>matches</code> where <code>matches</code>.<code>team_one_id, team_two_id</code> = 1 and <code>matches</code>.<code>team_one_id, team_two_id</code> is not null)</p>
  </blockquote>