I am new in neoeloquent. I have created some node which has some child nodes. But I can't figure out how do I get the data of the parent node from the child node?
Asked
Active
Viewed 191 times
1 Answers
0
This is a recursive relationship. In the Model, you just need to setup relationships as follows, assuming your keys are setup correctly. Then you can load the relationship using the with('parent)
or load('parent)
methods in your query.
Relationships:
//Node.php
public function children(){
return $this->hasMany('App\Node', 'parent_id', 'id');
}
public function parent(){
return $this->belongsTo('App\Node', 'parent_id', 'id');
}

Yat23
- 181
- 4