Here is how we can get all childs recursively from a parent id. You should have two columns in your table, Child_id & Parent_id then the method below will catch all nodes from parent to child infinitely.
public function buildCatTable($parent = 0 ,$level=1,&$tree=[]) {
$getStmt = GrTabsChildParentRelationships::find()->select(['tab_id', 'parent_tab_id'])->where(['parent_tab_id'=>$parent])->asArray()->all();
foreach($getStmt as $cat) {
$tree[]=$cat;
$this->buildCatTable($cat['tab_id'] ,$level +1,$tree);
}
$tree = json_encode($tree);
$tree = json_decode($tree, true);
return $tree;
}