Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Lars-Janssen's avatar

Laravel using roles in view

Right now I've this in my navbar.blade.php:

 @if (Auth::check()) 
       <li><a href="users/logout">Uitloggen</a></li>      
 @else
      <li><a href="/public/users/login">Inloggen</a></li>
        <li><a href="/public/users/register">Registreer</a></li> 
 @endif 

Now I've made a middleware called UserRoles.php and in here I can check for example if someone is an admin.

But how can I use this in my view for showing specific things in the navbar. For example an admin has a menu item: "show users", but a normal user hasn't. I know you can use middleware in your routes.php file or in your controllers constructor but I can't figure out how this works in my view.

0 likes
2 replies

Please or to participate in this conversation.