title: Return Eloquent Relationship Dependent on Value of Field in Model
body: <p>Say I have a Model, and I want to return a relationship, but it depends on a value of an attribute of the model. I tried this in my model:</p>
  
  <pre><code>public function paymentType(){
      if($this-&gt;type &gt; 1) return $this-&gt;hasOne(PaymentType::class, 'type', 'type');
      if($this-&gt;type == 1) return $this-&gt;hasOne(PaymentType::class, 'payment_type', 'pay_type');
  }
  </code></pre>
  
  <p>When I have an instance of the model, I can call this relationship fine, however when I try to eager load, and call <code>with('paymentType')</code>, I get the exception <code>Call to a member function addEagerConstraints() on null</code></p>