I'm doing a Laravel 9 project and I would like to realize a user management. I made a template with a basic header and I would like to know how to make a condition for this link (user management). If the session has an iduser with an administrator type, then I want it to show me the link. I show you my code :
<header>
<div class="button-burger" id="button-burger">
<button class="burger" id="button-burger">
<img src="/img/icons/burger.png" alt="" class="burger" id="burger">
</button>
</div>
<div class="bloc-logo">
<img src="{{ asset('img/templates/logo.png') }}" alt="Fallout" class="bigger-logo">
</div>
<div class="bloc-links" id="bloc-links">
<div class="link">
<a href="/" class="linky">Accueil</a>
</div>
<div class="link">
<a href="#" class="linky">Abris</a>
</div>
<div class="link">
<a href="#" class="linky">Boutique</a>
</div>
<div id="nuka-link" class="link">
<a href="/nuka-world" class="linky">Nuka World</a>
</div>
<div class="link">
<a href="#" class="linky">Gestion d'utilisateur</a>
</div>
<div class="link">
<a href="#" class="linky">Contact</a>
</div>
@if (Session::has('iduser'))
<div class="link">
<a href="/mon-profil" class="linky">Mon profil</a>
</div>
<div class="link">
<a href="/deconnexion" class="linky">Déconnexion</a>
</div>
@else
<div class="link">
<a href="/connexion" class="linky">Se connecter</a>
</div>
@endif
</div>
</header>
How can I do that please ? Thanks !
you can retrieve the user id through request()->user()->id
to check if the user is an admin. Or you can create an isAdmin()
method in your User model to see if an user is an admin and then call it this way:
@if(request()->user()->isAdmin())