2017-07-19 135 views

回答

0

這是遞歸關係。在模型中,假設您的密鑰設置正確,您只需按如下方式設置關係。然後,您可以在查詢中使用with('parent)load('parent)方法加載關係。

關係:

//Node.php 

public function children(){ 
    return $this->hasMany('App\Node', 'parent_id', 'id'); 
} 

public function parent(){ 
    return $this->belongsTo('App\Node', 'parent_id', 'id'); 
}