コード例 #1
0
ファイル: MenuController.php プロジェクト: zedx/core
 /**
  * Display a listing of the resource by group.
  *
  * @return \Illuminate\Http\Response
  */
 public function filterByGroupName($groupName)
 {
     $groups = $this->getGroups();
     $menus = Menu::whereGroupName($groupName)->orderBy('lft')->get()->toHierarchy();
     return view_backend('menu.index', compact('menus', 'groupName', 'groups'));
 }
コード例 #2
0
ファイル: helpers.php プロジェクト: zedx/core
 /**
  * Render Menu.
  *
  * @param string/Menu $groupName
  * @param array       $config
  *
  * @return void
  */
 function renderMenu($groupName, $config = [], $first = true)
 {
     $render = '';
     if (is_string($groupName)) {
         $nested = Menu::whereGroupName($groupName)->orderBy('lft')->get();
         if (!$nested) {
             return;
         }
         $menus = $nested->toHierarchy();
     } else {
         $menus = $groupName;
     }
     foreach ($menus as $menu) {
         if ($menu->type == 'page') {
             $page = Page::find($menu->link);
             $url = $page ? route('page.show', $page->shortcut) : '#';
         } elseif ($menu->type == 'route') {
             $url = Route::has($menu->link) ? route($menu->link) : '#';
         } else {
             $url = starts_with($menu->link, '/') ? url($menu->link) : $menu->link;
         }
         $active = url()->current() == $url ? 'active' : '';
         $hasChildren = $menu->children()->count() > 0;
         $element = $first ? 'parent' : 'children';
         $attrType = $hasChildren ? 'withChildren' : 'withoutChildren';
         $li = str_replace('{active}', $active, array_get($config, $element . '.li.' . $attrType, 'class="{active}"'));
         $liChildren = array_get($config, $element . '.liChildren');
         $link = array_get($config, $element . '.link.' . $attrType);
         $ul = array_get($config, $element . '.ul');
         $caret = $hasChildren ? array_get($config, $element . '.angle', '<span class="caret"></span>') : '';
         $render .= '<li ' . $li . '>' . '  <a href="' . $url . '" ' . $link . '>' . '    <i class="' . $menu->icon . '"></i> ' . $menu->name . ' ' . $caret . '  </a>';
         if ($hasChildren) {
             $render .= '<ul ' . $ul . '>';
             $render .= renderMenu($menu->children, $config, false);
             $render .= '</ul>';
         }
         $render .= '</li>';
     }
     return $render;
 }