简体   繁体   English

如何在模板视图中的laravel上创建子菜单?

[英]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). 我有表: menurolemenu_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.

相关问题 如何在Laravel 5的刀片模板中创建变量以供部分视图使用 - How to create a variable in a blade template in laravel 5 to be used by a partial view 如何使用 PHP/Laravel 创建、重命名、删除、拖放的上下文菜单创建 JSTree 视图? 这是完整的解决方案 - How to create a JSTree view with context menu with create, rename, delete, drag'n'drop with PHP/Laravel? This is the Full solution 如何在laravel中创建子域 - How to create a sub- domain in laravel 如何在 Laravel 5 中的视图模板上显示会话数据 - How to display session data on view template in Laravel 5 如何动态创建Wordpress仪表板子菜单页面? - How to create wordpress dashboard sub menu pages dynamically? 如何创建多个子菜单及其数据库结构? - How to create multiple sub menu and its database struture? 如何为生产或子域系统创建 laravel 存储符号链接? - How to create laravel storage symbolic link for production or sub domain system? 如何在Laravel中创建具有无限子页面的路由? - How to create routes with unlimited sub-pages in Laravel? 如何使用laravel 5中的输入名称创建存储文件夹和子文件夹 - How to create storage folder and sub folder using input names in laravel 5 如何在资源/视图目录Laravel中创建文件 - How to create a file in resource/view directory Laravel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM