简体   繁体   中英

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

I'm using Voyager, and I would like to solve, if the user is admin, see one more menu item in the welcome page.

Thank you in advance for the answers!

<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>

You can check for the role of the authenticated user inside your view. Maybe something like this:

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

您可以从控制面板轻松执行此操作 转到相应的角色并删除该模型的权限,它将从该用户的菜单中删除 例如:如果您想从菜单中隐藏 Media特定角色或每个角色,转到该角色并取消选中“浏览媒体”。

  • You can simply login to the dashboard
  • Click on the edit button for that particular role
  • check and uncheck what you want that role permission

visit Voyager Academy Roles Permisson for more information

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM