title: Laravel relations with composite, non-standard foreign keys
body: <p>I unfortunately need to import data from a third-party vendor and use their non-standard database schema with my laravel project. In addition, I need to store multiple "firms," each with their own set of users in my database. </p>
  
  <p>I'm trying to figure out the best way (if it can be done) to use Eloquent to handle the relationships between these tables. So for instance, with my table structure like this:</p>
  
  <pre><code> BmPerson
    'id',
    'firmId',
    'personId'
  
  BmCoverage
    'id',
    'firmId',
    'personId',
    'securityId'
  
  BmSecurity
    'id',
    'firmId',
    'securityId'
  </code></pre>
  
  <p>... for instance, I need to associate a "BmPerson" with many "BmSecurity" through the "BmCoverage" table. </p>
  
  <p>But I need to somehow use composite keys, because I am storing multiple "firms" in each table (per the 3rd party vendor's database schema).</p>
  
  <p>One approach I've used so far is scoping, e.g.: for my BmCoverage model:</p>
  
  <pre><code> public function scopeFromFirm($query,$firmId){
    return $query-&gt;where('firmId','=',$firmId);//-&gt;where('personId','=',$personId);}
  
  public function scopeFromPerson($query,$personId){
    return $query-&gt;where('personId','=',$personId);//-&gt;where('personId','=',$personId);}
  </code></pre>
  
  <p>Then I can retrieve the coverage list for an individual person, but I still need to somehow be able to associate the "BmCoverage" with the "BmSecurities." I suppose I could just add a scope the BmSecurities class too, but it would be nicer to just use Eloquent.</p>
  
  <p>Has anyone come up with a good way to use composite keys in laravel model relationships, or should I just stick with the scoping method?</p>