Generate tree menu with Dropdown - Cakephp 3.8

I created a menu of categories using tree in cakephp3. I can add, edit, display and everything. However, I can’t generate the dropdown menu because I have doubts to manipulate the submenus items (children).

I’m doing it that way

    public function display()
    {
        $this->viewBuilder()->setLayout('loja');
        $this->loadModel('Categorias');
        $item = $this->Categorias->find('all');
        $this->set('list', $item);
    }

And exhibiting like this:

<div class="md-accordion accordion" id="accordionEx" role="tablist" aria-multiselectable="true">
        <div class="card">
      <div class="card-title blue-gradient" style="height: 40px">
        <p class="card-text white-text mt-2 ml-4">Departamentos</p>
      </div>
            <?php foreach ($list as $categoria): ?>
          <button type="button" class="list-group-item list-group-item-action">
            <?= h($categoria->nome) ? $this->Html->link($categoria->nome, ['controller' => 'Categorias', 'action' => 'buscar_categorias', $categoria->id]) : '' ?>
          </button>
          <?php endforeach; ?>
    </div>

But they are like a list, one above the other. I cannot distinguish between submenus. The idea was to organize this as in the image, but the question arises as to how to handle the child items.

tela

code referring to the image:

<div class="sidenav">
  <a href="#about">About</a>
  <a href="#services">Services</a>
  <a href="#clients">Clients</a>
  <a href="#contact">Contact</a>
  <button class="dropdown-btn">Dropdown 
    <i class="fa fa-caret-down"></i>
  </button>
  <div class="dropdown-container">
    <a href="#">Link 1</a>
    <a href="#">Link 2</a>
    <a href="#">Link 3</a>
  </div>
  <a href="#contact">Search</a>
</div>

Thanks for any comment!