Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * Remove the specified resource from storage.
  *
  * @param int $id
  *
  * @return \Illuminate\Http\Response
  */
 public function destroy(Menu $menu)
 {
     $menu->delete();
 }
Ejemplo n.º 3
0
 protected function create($name, $title, $group, $icon, $link, $type)
 {
     return Menu::create(['name' => $name, 'title' => $title, 'group_name' => $group, 'icon' => $icon, 'link' => $link, 'type' => $type]);
 }