laravel刀片-如何隐藏特定路线的html元素的显示

时间:2018-08-30 18:13:47

标签: laravel laravel-routing laravel-blade

人们!

我正在使用安装了Hyn Laravel-Tenancy的Laravel 5.6。

我有一个对所有租户(子域)都相同的主菜单,但是,对于一个或另一个特定租户(子域),我希望从该主菜单中显示某些项目,但对于所有其他租户,这些菜单项即使被URL调用也不可见,也无法访问。

在刀片服务器上,我使用了“ @if route :: has”,但即使将该路由限制为特定的子域,该路由也可用于所有其他子域,因此@if接收为true并最终显示菜单项目。

我没有找到一个简单的解决方案,可以创建一个可识别url的帮助程序,如果它来自特定的子域,则将显示该项目,而其他子域将不会显示,但是“我猜”它应该使用Blade与“ routes \ web”一起使用本机表单来实现此结果。

谢谢!

routes\web.php

enter image description here

2 个答案:

答案 0 :(得分:1)

使用门并可以在laravel中 在authserviceprovider中创建一个像这样的门:

 $gate->define('see-menu',function(){
            //check domains or rules or every thing that you need to check to obtain access
           //return true if user have access and false if not access
            });

在您看来,可以使用它查看菜单

@can('see-menu')
//your code 
         <li class="devider"></li>.......
@endcan

答案 1 :(得分:0)

u可以做到这一点,就像我让我的溃败“管理部门listOfTeachers”那样,让用户可以看到侧面菜单的按钮并使用它

 @if(Request::is('admin') || Request::is('department') || Request::is('listOfTeachers'))
              <div id="mySidenav" class="sidenav">
                <a href="javascript:void(0)" class="closebtn" onclick="closeNav()" style="font-size:40px;">&times;</a>
                <a href="{{ url('main') }}" style="margin-top:30%;text-align: right;" class="sidenavbuttons"><p id="poficon2" style="font-family: AwesomeFont;font-size: 27px; float: right;width:auto;height:auto;padding-left: 15px;padding-right: 20px;" class="colorIcon" id="newbornbaby"></p><p style="font-size: 23px;">الرئيسية</p></a>
                <a href="{{ url('listOfCandidates') }}" style="text-align: right;" class="sidenavbuttons"><p id="poficon2" style="font-family: AwesomeFont;font-size: 27px; float: right;width:auto;height:auto;padding-left: 15px;padding-right: 20px;" class="colorIcon" id="newbornbaby"></p><p style="font-size: 23px;">قائمة المترشحين</p></a>
                <a href="{{ url('listOfTeachers') }}" style="text-align: right;"  class="sidenavbuttons"><p id="poficon2" style="font-family: AwesomeFont;font-size: 27px; float: right;width:auto;height:auto;padding-left: 15px;padding-right: 20px;" class="colorIcon" id="newbornbaby"></p><p style="font-size: 23px;">قائمة الاساتذة</p></a>
                <a href="{{ url('department') }}" style="text-align: right;"  class="sidenavbuttons"><p id="poficon2" style="font-family: AwesomeFont;font-size: 27px; float: right;width:auto;height:auto;padding-left: 15px;padding-right: 20px;" class="colorIcon" id="newbornbaby"></p><p style="font-size: 23px;">الشعب و التخصصات</p></a>
                <a href="{{ url('workersAccounts') }}"  style="text-align: right;" class="sidenavbuttons"><p id="poficon2" style="font-family: AwesomeFont;font-size: 27px; float: right;width:auto;height:auto;padding-left: 15px;padding-right: 20px;" class="colorIcon" id="newbornbaby"></p><p style="font-size: 23px;">حسابات العمال</p></a>
              </div>

                <div class="centerVertical" style="float:right;margin-right:1.2rem;" onclick="openNav()">
                    <img src="../resources/images/menu.png" style="margin-top:3px;float:left;width:27px;height:20px;background-size: contain;background-repeat: no-repeat;" alt="student">
                </div>

              @endif