@if( !empty(config('sidebar.menu')[$ROLE]) ) {{ MENU::print( config('sidebar.menu')[$ROLE], config('sidebar.const.SIDEBAR_CROP_ON'), config('sidebar.const.SIDEBAR_SEARCH_ON') ) }} @endif @push('style') @endpush @push('script') @endpush @push('ready') @endpush @php abstract class MENU{ private static $page; /** * PRINT THE CORRESPNDING MENTU FOR THE USER */ public static function print($items, $crop=true, $search=true){ // UPDATE CURRENT PAGE TO THIS self::$page = request()->route()->getName(); echo '
'; } /** * MENU PRINT FUNCTION */ public static function printMenu($items, $submenu=false){ $menu = ''; for ($i=0; $i{$item[0]}"; $link = isset($item[1]) ? $item[1] : 'javascript:;'; $icon = isset($item[2]) ? "":''; $active = ($link==self::$page) ? 'class="active"' : ''; # BASE CASE if(is_string($link)){ $link_tag = Route::has($link) ? route($link) : $link; return "
  • $icon $label
  • "; } if(is_array($link)){ return "
  • $icon $label
  • '; } } # GIVE A FLAT ARRAY WITH THE LINK PAGES public static function flatMenu($menu, &$pages){ foreach($menu as $link){ $label = $link[0]; $target = $link[1]; if(is_string($target)){ $pages[$label] = $target; } if(is_array($target)) self::flatMenu($target, $pages); } return $pages; } # FIND A KEYWORD PATH public static function findPath($menu, $needle, &$path=[], &$found=false){ // FOREACH ELEMENT IN LINEAR MENU foreach($menu as $link){ // SET BOARD $label = $link[0]; $target = $link[1]; if($label===$needle){ $path[] .= $label; $found = true; } // STOP CHECKING IN LINEAR ARRAY if($found) break; // CHECK DEEPER if(is_array($target)){ self::findPath($target, $needle, $path, $found); if($found){ // UPDATE PATH $path[] .= $label; } } } return array_reverse($path); } } @endphp