如何显示第三个子菜单?

问题描述 投票:0回答:0

我想在 Laravel 中创建一个带有子菜单的菜单。我写了这段代码,但它没有显示第三个子菜单。

比如我要显示

Another dropdown
的子菜单。但它没有显示。

<ul class="navbar-nav me-auto mb-2 mb-lg-0">
  @foreach($categories->where('parent_id', 0) as $category)
    @if($category->children->count() > 0)
      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="true">{{ $category->title }}</a>
        <ul class="dropdown-menu shadow" data-bs-popper="static">
          @foreach($category->children as $children)
            @if($children->children->count() > 0)
              <li class="dropend">
                <a href="{{ $children->path() }}" class="dropdown-item dropdown-toggle" data-bs-toggle="dropdown">{{ $children->title }}</a>
                <ul class="dropdown-menu shadow">
                  @foreach($children->children as $child)
                    <li class="dropend">
                      <a class="dropdown-item dropdown-toggle" data-bs-toggle="dropdown" href="{{ $child->path() }}">{{ $child->title }}</a>
                      <ul class="dropdown-menu dropdown-submenu shadow">
                        @foreach($child->children as $childs)
                          <li class="nav-item">
                            <a class="nav-link" href="{{ $childs->path() }}">{{ $childs->title }}</a>
                          </li>
                        @endforeach
                      </ul>
                    </li>
                  @endforeach
                </ul>
              </li>
            @endif
          @endforeach
        </ul>
      </li>
    @endif
  @endforeach
</ul>

Category.php

public function children ()
{
    return $this->hasMany(Category::class, 'parent_id', 'id');
}

你能帮我看看如何实现吗?我试过使用几个引导程序类,甚至硬编码左右浮动。没有任何帮助。我的代码在上面:

laravel bootstrap-5
© www.soinside.com 2019 - 2024. All rights reserved.