/** * Run the database seeds. * * @return void */ public function run() { ///////// // Find root menu. $menuRoot = Menu::where('name', 'root')->first(); // Create Demo container. $menuPackageHome = Menu::create(['name' => 'package-home', 'label' => 'sroutier/menu-builder', 'icon' => 'fa fa-github', 'separator' => false, 'url' => "https://github.com/sroutier/menu-builder", 'enabled' => true, 'position' => 0, 'parent_id' => $menuRoot->id]); $menuHome = Menu::create(['name' => 'home', 'label' => 'Home', 'icon' => 'fa fa-home', 'separator' => false, 'url' => "/", 'enabled' => true, 'position' => 1, 'parent_id' => $menuRoot->id]); $menuDemo = Menu::create(['name' => 'demo', 'label' => 'Demo', 'icon' => 'fa fa-book fa-colour-blue', 'separator' => false, 'url' => "/menu-builder-demo/home", 'enabled' => true, 'position' => 2, 'parent_id' => $menuRoot->id]); // Create Sub menu 1 container. $menuDemoSub1 = Menu::create(['name' => 'sub-menu-1', 'label' => 'Sub menu 1', 'icon' => 'fa fa-bookmark', 'separator' => false, 'url' => "/menu-builder-demo/one", 'enabled' => true, 'position' => 0, 'parent_id' => $menuDemo->id]); // Create Sub menu 2 container. $menuDemoSub2 = Menu::create(['name' => 'sub-menu-2', 'label' => 'Sub menu 2', 'icon' => 'fa fa-bookmark-o', 'separator' => false, 'url' => "/menu-builder-demo/two", 'enabled' => true, 'position' => 1, 'parent_id' => $menuDemo->id]); // Create Admin container. $menuAdmin = Menu::create(['name' => 'admin', 'label' => 'Admin', 'icon' => 'fa fa-cog fa-colour-red', 'separator' => false, 'url' => null, 'enabled' => true, 'position' => 999, 'parent_id' => $menuRoot->id]); // Create Menus sub-menu $menuMenus = Menu::create(['name' => 'menus', 'label' => 'Menus', 'icon' => 'fa fa-bars', 'separator' => false, 'url' => "/admin/menus", 'enabled' => true, 'position' => 0, 'parent_id' => $menuAdmin->id]); }
/** * @param null $leaf * @return mixed|null * @throws MenuBuilderMenuItemNotFoundException */ public function getLeafMenuItem($leaf = null) { // Get the leaf menu item from the value passed in. try { $leaf = $this->getMenuItem($leaf); return $leaf; } catch (MenuBuilderMenuItemNotFoundException $ex) { // Eat the exception as we want a chance to find it from the current route. } // find by current URL... $currentUrl = $this->getCurrentUrl(); $leaf = Menu::where('url', $currentUrl)->first(); if ($leaf instanceof Menu) { return $leaf; } // Could not find the requested menu item, throwing an exception. throw new MenuBuilderMenuItemNotFoundException("Menu item [" . $leaf . "] not found for URL [" . $currentUrl . "]."); }