A
A
Artyom2019-05-29 17:22:52
Laravel
Artyom, 2019-05-29 17:22:52

Why is it not output via @foreach laravel?

There is a header.blade.php file that includes the top_menu.balde.php file, which is responsible for the menu.
if you just write something in top_menu.balde.php, then it is displayed in the place where the menu should be, and if you write something inside "@foreach" then it is not displayed, what could be the problem?

@foreach ($categories as $category)

    @if ($category->children->where('published', 1 )->count())
      <li class="dropdown">
      <a href="{{url("/blog/category/$category->slug")}}" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
      {{$category->title}} <span class="caret"></span>
      </a>
      <ul class="dropdown-menu" role="menu">
        @include('layouts.top_menu', ['categories'=>$category->children])
      </ul>
    @else
        <li>
        <a href="{{url("/blog/category/$category->slug")}}">{{$category->title}}</a>
        

    @endif      
        </li>
@endforeach

Here I connect the top menu and pass the variable
<ul class="nav navbar-nav">
                @include('layouts.top_menu', ['categories' => $categories])
            </ul>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artyom, 2019-05-29
@danyvasnafig

Solved the problem, I made the output only published categories, with a value of 1, and all my previously created ones were not published (value 0)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question