簡體   English   中英

Laravel Voyager:如果用戶是管理員,則只能看到菜單項

[英]Laravel Voyager: only see a menu item if the user is admin

我正在使用 Voyager,我想解決,如果用戶是管理員,請在歡迎頁面中再看到一個菜單項。

提前感謝您的回答!

<body>
  <div class="flex-center position-ref full-height">
    @if (Route::has('login'))
      <div class="top-right links">
        @auth
          <a href="{{ url('/home') }}">Home</a>
        @else
          <a href="{{ route('login') }}">Login</a>
          <a href="{{ route('register') }}">Register</a>
        @endauth
      </div>
    @endif

    <div class="content">
      <div class="title m-b-md">
        Laravel
      </div>

      <div class="links">
        <a href="https://laravel.com/docs">Documentation</a>
        <a href="https://laracasts.com">Laracasts</a>
        <a href="https://laravel-news.com">News</a>
        <a href="https://forge.laravel.com">Forge</a>
        <a href="https://github.com/laravel/laravel">GitHub</a>
      </div>
    </div>
  </div>
</body>

您可以在視圖中檢查經過身份驗證的用戶的角色。 也許是這樣的:

@if (Auth::user()->hasRole('admin'))
    <a href="...">This can only be seen by admins</a>
@endif

您可以從控制面板輕松執行此操作 轉到相應的角色並刪除該模型的權限,它將從該用戶的菜單中刪除 例如:如果您想從菜單中隱藏 Media特定角色或每個角色,轉到該角色並取消選中“瀏覽媒體”。

  • 您只需登錄儀表板即可
  • 單擊該特定角色的編輯按鈕
  • 選中並取消選中您想要的角色權限

訪問航海者學院角色許可了解更多信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM