I want to loop through database fields till I find the mother of all children. When I echo the $page->id
in the findMother()
function (instead of returning it) it gives me the correct page id
, but it doesn't return it to the second function.
private function findMother($id) {
$page = Page::find($id);
if($page->parent_id != 0 || $page->parent_id != null) {
$this->findMother($page->parent_id);
} else {
// if I echo the $page->id here it shows me the correct mother page id
return $page->id;
}
}
private function loadSubPages($api) {
$page = Page::where('api', $api)->first();
$mother = $this->findMother($page->id);
die('mother: ' . $mother); // $mother is empty
}
Anybody have an idea what I am missing here?