laravel - 我正在尝试使用 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>
解决方案
你可以这样使用
<span>
{{$menu->name}}
@if($menu->name=='property')
{{propertyCount()}}
@endif
</span>
推荐阅读
- regex - 正则表达式不仅适用于空格
- r - R 是否有 += 和 -= 运算符的实现?
- reactjs - npm 包的实际重量是多少?
- python - 创建一个列,根据条件删除不需要的字符串部分
- python - 使用 matplotlib 时,AttributeError: 'numpy.datetime64' object has no attribute 'toordinal'
- python - 以特定模式重复字符串而不切片
- java - 如何使用 React Native 关闭像 modal 这样的组件?
- angular - Typescript:通用类型检查和子可用性
- java - 如何传递 id 是否正确?我不明白错误?
- javascript - Client.db 未定义(MongoDB 后端 API)错误