[英]how to create a sub menu on laravel in template view?
i want to create a sub menu on my templates/master. 我想在模板/主模板上创建一个子菜单。 i want all my process in there.
我想要我所有的流程。 i have table:
menu
, role
, and menu_role
(conatins many to many from menu and role). 我有表:
menu
, role
和menu_role
(从菜单和角色中包含很多对很多)。
i tried to select table menu through menu_role, because i want display menu according to its role. 我试图通过menu_role选择表菜单,因为我想根据其角色显示菜单。 it success but there is no sub menu.
成功,但是没有子菜单。 i'm bad at query builder with relationship.
我不擅长与关系的查询生成器。
this is my templates/master.blade.php
: 这是我的
templates/master.blade.php
:
use App\MenuRole;
use App\Role;
use App\Menu;
use App\Admin;
use App\Operator;
$userCheck = Auth::user()->role_id;
$menus = MenuRole::with('menu')->where('role_id', $userCheck)->get();
and for the html, if there is no module on table menu i want to display this : 对于html,如果表格菜单上没有模块,我想显示以下内容:
@foreach($menus as $menu)
<li><a href="/{{ Auth::user()->role->role_name }}/{{ $menu->menu->route }}" target="{{ $menu->menu->target }}">{{ $menu->menu->title }}</a></li>
@endforeach
and if there is a module
, i want to display this : 如果有一个
module
,我想显示此:
<li class="has-sub">
<a class="js-arrow" href="#">
<i class="fas fa-tachometer-alt"></i>{{ $menu->module }}</a>
<ul class="navbar-mobile-sub__list list-unstyled js-sub-list">
<li><a href="/{{ Auth::user()->role->role_name }}/{{ $menu->menu->route }}">{{ $menu->menu->title }}</a></li>
</ul>
</li>
so the thing is, in table menu i have field module
. 所以问题是,在表格菜单中我有一个field
module
。 this field will distinguish which ones have subMenu and which have no subMenu. 此字段将区分哪些具有子菜单,哪些没有子菜单。 and i want to
foreach
table menu. 我想
foreach
表菜单。 i have configure the model. 我已经配置了模型。
Will a simple @empty
condition suffice? 一个简单的
@empty
条件就足够了吗? When a Menu has the module
field filled it shows one thing, otherwise the other. 当菜单中的
module
字段填满时,它将显示一件事,否则显示另一件事。
@foreach ($menus as $menu)
@empty($menu->menu->module)
@else
@endempty
@endforeach
If this does not solve your problem, could you please go into more detail about what you want it to look like? 如果这不能解决您的问题,能否请您进一步介绍您希望它看起来像什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.