首页 > 解决方案 > 我正在尝试使用 laravel 8 显示特定名称的计数

问题描述

我正在尝试显示特定名称的计数,即左侧菜单名称“属性”,但在所有菜单中显示计数请帮助我如何使用 laravel 8 仅在属性菜单上显示计数

助手.php

function propertyCount()
 { 

    $propertyModelPath = Menu::where('route', 
   'property')->where('count_show', 1)->first();

    $modelClass = $propertyModelPath->modal_path;

    $count = new $modelClass;

    return $count->count();
}

左侧栏菜单

<div id="sidebar-menu">
      <ul>
        @foreach ($menus as $menu)
          @if ($menu->parent_id == 0)
          <li class="has_sub">
            <a href="{{$menu->route == null ? 'javascript:void(0);' : route($menu->route)}}" class="waves-effect">
              <i class="{{$menu->icon}}"></i>
              <span> {{$menu->name}} {{propertyCount()}}  </span>
              @if ($menu->route == null)
              <span class='menu-arrow'></span>
              @endif
            </a>
          </li>
          @endif
        @endforeach
      </ul>
      <div class="clearfix"></div>
    </div>
    <div class="clearfix"></div>
  </div>
</div>

标签: laravel

解决方案


你可以这样使用

<span> 
    {{$menu->name}} 
    @if($menu->name=='property')
        {{propertyCount()}}  
    @endif
</span>

推荐阅读