mardi 27 décembre 2016

Configure navbar to show different buttons, when different type of users login Laravel 5.2

I Just wanted to ask this: I am doing a header in which I check if the user that is logged in, has an Admin or a User role. If he is an administrator, it must show Administration (the name of the button). If he is a user, it must show the name of the user's name along (the name of the button) with 2 dropdown links, profile and logout.

So far I have done this:

<li class="dropdown">
    @if ((Auth::check() && (Auth::user()->roles()->id=1)) //Administration area
        <a href="" role="button" aria-haspopup="true" aria-expanded="false" ><i class="fa fa-user fa-2x" aria-hidden="true"></i> Administration</a>
    @elseif(Auth::check() && (Auth::user()->roles()->id=3)) //Simple user area
        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" ><i class="fa fa-user fa-2x" aria-hidden="true"></i>  <span class="caret"></span></a>
    <ul class="dropdown-menu">
        <li><a href="">User Profile</a></li>
        <li><a href="">Log out</a></li>
    </ul>
    @else
        @include('user.login') //login area
    @endif
</li>

When no users are logged in, the login button is being shown.

When a users is logged in, eg a User, it shows me Administrator button, the 1st If. But that's wrong.

It doesn't seem to get out of the If and can't see why.

I must say that I access roles table via a pivot table user_role that's why I use user()->roles()->id. When I had roles inside users table, it was working. Does anyone has any idea? Anything would be appreciated!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2i6hhs6
via IFTTT

Aucun commentaire:

Enregistrer un commentaire