我正在插入动态菜单,但是在获取动态下拉菜单时遇到问题。
当我单击子菜单时,它将重定向到该子菜单页面,但是从那里将不会重定向到第三级菜单,当我单击索引中的第三级菜单并且无法从第三级访问第二级菜单时,会出现相同的问题菜单页面。
控制器:
public function subcategory($subcat_name)
{
$flag = false;
$menus = Categorymodel::get();
$submenus = SubmenuModel::get();
$third_levelmenus = SubcategoryModel::get();
$viewSubcategory=DB::table('subcategory')->select('cat_id','subcat_name','subcat_description')->where('subcat_name',$subcat_name)->get();
foreach($viewSubcategory as $viewSubcategorys)
{
$cat_id=$viewSubcategorys->cat_id;
}
$viewcategory=DB::table('category')->select('category_name')->where('id',$cat_id)->get();
return view('subcategory',compact('menus','submenus','third_levelmenus'),['viewSubcategory' => $viewSubcategory,'viewcategory' =>$viewcategory,'flag' => $flag]);
}
public function thirdLevelMenus($subcategory_cat)
{
$flag = false;
$menus = Categorymodel::get();
$submenus = SubmenuModel::get();
$third_levelmenus = SubcategoryModel::get();
$thirdLevelMenu=DB::table('subcategory_cat')->select('subcat_id','category_name','subcategory_description','subcategory_cat')->where('subcategory_cat',$subcategory_cat)->get();
foreach($thirdLevelMenu as $thirdLevelMenus)
{
$subcat_id=$thirdLevelMenus->subcat_id;
}
$viewsubcategories=DB::table('subcategory')->select('subcat_name','cat_id')->where('id',$subcat_id)->get();
foreach($viewsubcategories as $viewsubcategorie)
{
$cat_id=$viewsubcategorie->cat_id;
}
$viewcategories=DB::table('category')->select('category_name')->where('id',$cat_id)->get();
return view('third-level-menus',compact('menus','submenus','third_levelmenus'),['thirdLevelMenu' => $thirdLevelMenu,'viewsubcategories' =>$viewsubcategories,'viewcategories'=>$viewcategories,'flag' => $flag]);
}
查看:
@if($flag)
@foreach($menus as $menu)
@if($menu->status==1)
<li class="nav-item dropdown">
<a class="nav-link abouts" href="#" id="{{$menu->id}}">{{ $menu->category_name }}</a>
@if(!$submenus->isEmpty())
<ul class="dropdown-menu">
@foreach($submenus as $submenu)
@if($submenu->status==1)
@if($submenu->cat_id == $menu->id)
<li class="submenu">
<a href="#subcategory/{{$submenu->subcat_name}}/{{$submenu->id}}" class="{{$submenu->id}}">{{ $submenu->subcat_name }}</a>
@if(!$third_levelmenus->isEmpty())
<ul class=" third_level">
@foreach($third_levelmenus as $third_levelmenu)
@if($third_levelmenu->status==1)
@if($submenu->id == $third_levelmenu->subcat_id)
<li><a href="third-level-menus/{{$third_levelmenu->subcategory_cat}}">{{ $third_levelmenu->subcategory_cat }}</a></li>
@endif
@endif
@endforeach
</ul>
@endif
</li>
@endif
@endif
@endforeach
</ul>
@endif
</li>
@endif
@endforeach