title: How can Laravel / Eloquent's hasMany relationship have a local key?
body: <p>In laravel, when a single entry in table A (e.g. Users) is associated with many entries in table B (e.g. Payment Methods), we define a <a href="http://laravel.com/docs/4.2/eloquent#one-to-many" rel="nofollow">"has many" relationship.</a></p>
  
  <p>So, in User.php model we set:</p>
  
  <pre><code>return $this-&gt;hasMany('PaymentMethods', 'foreign_key', 'local_key');
  </code></pre>
  
  <p>The foreign key makes sense, e.g. it could be <code>userid</code>, because each entry in the payment methods table B will have only 1 user. However, why can a local key be set here? How can the users table ever have a "payment method" id key when it is associated with many payment methods, and therefore cannot be set to a single payment method id?</p>
  
  <p>Similarly, to complete the relationship, I have to define a belongsTo in the PaymentMethod.php model:</p>
  
  <pre><code> return $this-&gt;belongsTo('User');
  </code></pre>
  
  <p>In here, should one only set the second parameter, i.e. the local key (e.g. to <code>userid</code>)?</p>