Exemplo n.º 1
0
 /**
  * Render a menu structure from the database
  *
  * @param string $menukey
  * @return string|null
  */
 public function make($menukey)
 {
     $menukey = Str::slug($menukey);
     $menu = Menu::where('slug', '=', $menukey)->first();
     $renderer = new LavarySidebarRenderer();
     return $renderer->renderToHtml($menu);
 }
 /**
  * Get the menu data to be passed to the menu->add function
  *
  * Lavary Menu requires an array of data to be passed to the menu->add()
  * function call.
  *
  * @param MenuModel $menuModel
  * @return array
  */
 protected function getMenuData(MenuModel $menuModel)
 {
     // Menu headers only have one class and no link.
     if ($menuModel->isRoot()) {
         return ['class' => 'header'];
     }
     $menu_data = array();
     // Provide a route if there is one in the table otherwise provide a URL.
     if (!empty($menuModel->route)) {
         $menu_data['route'] = $menuModel->route;
     } elseif (!empty($menuModel->url)) {
         $menu_data['url'] = $menuModel->url;
     }
     // If this node has children, make it a treeview
     if (!$menuModel->isLeaf()) {
         $menu_data['class'] = 'treeview';
     }
     return $menu_data;
 }
Exemplo n.º 3
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // Find the menu -- searching by slug is a good way to identify
     // menus.
     /** @var Menu $menu */
     $menu = Menu::where('slug', '=', 'example-menu')->first();
     // Create the renderer.
     $renderer = new LavarySidebarRenderer();
     // Use the renderer to render the menu to HTML.
     $rendered = $renderer->renderToHtml($menu);
     // Output the HTML to the console just as an example.
     $this->output->writeln($rendered);
 }
 public function run()
 {
     $nodes = $this->getNodes();
     // Build the above list of nodes as a heirarchical tree
     // of categories.
     foreach ($nodes as $node_name => $node_data) {
         // Create each root node.
         $root_node = Menu::create(['name' => $node_name, 'url' => $node_data['url']]);
         // Create the children of the root node.
         if (!empty($node_data['children'])) {
             $this->createNodes($root_node, $node_data['children']);
         }
     }
 }