V
V
Vladimir Kokhan2018-07-25 16:16:14
Laravel
Vladimir Kokhan, 2018-07-25 16:16:14

How to make a drop down menu in Laravel?

Good day everyone.
Please help me with this design. I have a drop down menu code

<div class="inbox content">
        <ul>
          @foreach($sitemap->where('parent', 0) as $item)
          <li>
            <a href="{{ $item->alias }}">{{ $item->title }}</a>
            @if($sitemap->where('parent', '>', 0)->count() > 0)
              <ul>
                @foreach($sitemap->where('parent', $item->id) as $value)
                  <li><a href="{{ $value->alias }}">{{ $value->title }}</a></li>
                @endforeach
              </ul>
            @endif
          </li>
          @endforeach
        </ul>
      </div>

Child items are only in the first two parent items. There are seven in total. In theory, there should not be a child tag in the remaining paragraphs . But for some reason he is, although without . How to get rid of it? Thanks <ul><li>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yan-s, 2018-07-25
@Yan-s

It will always be true here if there is at least 1 element with parent > 0 in $sitemap.
You need to change the design so that the check is for elements that have parent === $item->id, for example, as in the next foreach.

K
Krunal Lathiya, 2018-08-25
@KrunalLathiya

This article should answer your question: href=" https://appdividend.com/2018/02/23/laravel-5-6-cru... ">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question