I have a model CourseModule
, and each of the items are related to the same model.
here is the answer that can help you
I think you you have to do it recursively to retrieve whole tree:
$data = CourseModule::with('child_rec');
This may help you according to your requirement,
public function child()
{
return $this->hasMany('App\CourseModule', 'parent');
}
public function children_rec()
{
return $this->child()->with('children_rec');
// which is equivalent to:
// return $this->hasMany('App\CourseModule', 'parent')->with('children_rec);
}
// parent
public function parent()
{
return $this->belongsTo('App\CourseModule','parent');
}
// all ascendants
public function parent_rec()
{
return $this->parent()->with('parent_rec');
}