2013-08-12 2 views
1

웅변으로 역동적 인 관계를 유지할 수 있습니까? fkauteur 열이 'personeel를'동일한 경우Eloquent에서 동적 관계를 유지할 수 있습니까?

class OrderbonCommentaar extends Eloquent{ 
    public function auteur() 
    { 
     if ($this->attributes['fkauteur'] == 'personeel') { 
      return $this->belongsTo('Personeel', 'id_auteur'); 
     } else { 
      return $this->belongsTo('ContactPersoon', 'id_auteur'); 
     } 
    } 
} 

그래서는 Personeel 모델을로드해야합니다 :

$order = Order::with('commentaar', 'commentaar.auteur')->get(); 

그리고 내 Commentaar 모델

내가이 있습니다

나는 다음을 수행 싶습니다 그렇지 않으면 Contactpersoon 모델을로드해야합니다.

내가 제공 한 코드의 문제점은 관계를 호출 할 때 특성이 채워지지 않는다는 것입니다.

+0

로 본다. –

답변

0

예는, 때`영화 감독이()`를 호출,로드 된 속성이 없기 때문에 가능하지 않다 polymorphic relationships

관련 문제