public function makeChild($parent, $name, $children, $depths = []) { if (count($depths)) { $depth = array_shift($depths); } else { $depth = 7; } $child = new Region(['name' => $name, 'region_type_id' => $depth]); $child->makeLastChildOf($parent); foreach ($children as $name => $grandchildren) { $this->makeChild($child, $name, $grandchildren, $depths); } }