How to do multi level self join in laravel 5.4
i have table like this.
ID name ParentId
1 abc 0
2 acd 1
3 ads 1
4 xyz 2
5 xxy 2
6 plm 3
7 ytr 4
8 lks 6
Now i need:
# if i call id 1 it will return full tree under it.
# if i call it empty it will return full tree
# i did this
public function getParent() {
return $this->belongsTo(self::class, 'ParentId','id');
}
public function getChild(){
return $this->hasMany(self::class, 'ParentId','id');
}
its giving me single brunch but i need full of them.
some one plz help.