Tuesday, April 11, 2017

Navbar conditions in blade template user/admin Laravel

Sorry if the question is silly for you but seems like I can't figured t out. I have two functions isLogged and isAdmin. They work perfectly and based on them I want to create links on my navbar. What I'm trying is this

<li>Non Logged users link visible for everyone visiting the site</li>           
    @if(isLoggedIn() && !isAdmin())
        <li>LoggedIn Link</li>

            @if(isLoggedIn() || isAdmin())
                <li><a href="">Both</a></li>
            @endif      

        <li><a href="#">Logged In link</a></li> 
    @elseif(isAdmin())              

        <li><a href="#">Admin Dashboard</a></li>                                        
    @else           
        <li><a href="#">Login</a></li>
    @endif

Basically what I want to create here is

  1. All logged in users which aren't admins to have some links which aren't visible for admins.
  2. All logged in users which are admins to have different links which are visible only for them.
  3. All logged in users no matter admins or normal users to have addition links to their links.

@if -> (BaseController::isLoggedIn() && !BaseController::isAdmin()) checks if user is logged but not admin

then inside I've placed another if which should show <li><a href="">Both</a></li> on Admins and users since they are logged in... But I see this link only on logged in User. On Admin isn't visible.

I'm aware of ACL's but I don't really need acl. I want to accomplish this with conditions like this.

How to construct the conditions?



via VLS

Advertisement