Laravel Blade 中的类别子类别树显示

问题描述

该项目是电子商务。 任务是以树模式显示类别列表。 我获得了父子类别的所有信息(到刀片,从数据库中)。

image 1

这里的消费电子是当前选择的类别。 但是如果选择了任何类别,我想像这样过滤。

image 2

即 除了选中的类别及其父级和子级之外,不显示其他类别。

代码

@foreach($cats as $cat)
    
    <li class="filter-categories__item  @if ( URL::current() == $cat->url ) filter-categories__item--current @endif ">
        <a href="{{ $cat->url }}"> {!! str_repeat('&nbsp;&nbsp;&nbsp;',$level) !!} {{ $cat->name }} @if($cat->children->count()) + @endif </a>
        <div class="filter-categories__counter">{{ $cat->products_count }}</div>
    </li>

    @if ($cat->children->count() ) 
        @include(Theme::getThemeNamespace() . '::partials.listing-page.category-filter',['cats' => $cat->children,'level' => $level + 1 ])
    @endif

@endforeach

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)