/** * Create all of the child nodes of a root node. * * @param Menu $root_node * @param array $nodes */ protected function createNodes($root_node, $nodes) { foreach ($nodes as $node_name => $node_data) { // Create the highest level child node. $child_node_data = ['name' => $node_name]; if (!empty($node_data['url'])) { $child_node_data['url'] = $node_data['url']; } if (!empty($node_data['route'])) { $child_node_data['route'] = $node_data['route']; } $child_node = $root_node->children()->create($child_node_data); // Update the description, just for fun $child_node->description = $child_node->path; $child_node->save(); // Create all of the children of the child node, if there are any. if (!empty($node_data['children'])) { $this->createNodes($child_node, $node_data['children']); } } }