Say I have a model and I want to return the relationship, but it depends on the value of the model attribute. I tried this in my model:
public function paymentType(){
if($this->type > 1) return $this->hasOne(PaymentType::class, 'type', 'type');
if($this->type == 1) return $this->hasOne(PaymentType::class, 'payment_type', 'pay_type');
}
When I have an instance of the model, I can call this connection beautiful, however, when I try to load the load and call with('paymentType'), I get an exceptionCall to a member function addEagerConstraints() on null
source
share