Ben*_*Ben 5 php laravel eloquent
假设我有一个模型,我想返回一个关系,但它取决于模型属性的值.我在我的模型中试过这个:
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');
}
Run Code Online (Sandbox Code Playgroud)
当我有一个模型的实例时,我可以称这种关系很好,但是当我尝试加载并调用时with('paymentType'),我得到了异常Call to a member function addEagerConstraints() on null
| 归档时间: |
|
| 查看次数: |
1055 次 |
| 最近记录: |