If statement problem

Published 6 months ago by Ibe

Hi there, can someone help me please with my elseif structure?

What I have:

@if (Route::has('login'))
              <div class="top-right links">
                  @if (Auth::guard('admin'))
                      <a href="{{ url('/admin') }}">Home</a>

                  @elseif (Auth::guard('user'))
                  <a href="{{ url('/home') }}">Home</a>

                  @else
                      <a href="{{ url('/login') }}">Login</a>
                      <a href="{{ url('/register') }}">Register</a>
                  @endif

              </div>
@endif 

So the only part that is not working is the last part:

@else
        <a href="{{ url('/login') }}">Login</a>
        <a href="{{ url('/register') }}">Register</a> 

So what I want is when nobody is logged in, I want to show these links. But I always get the 'home' links...

ejdelmonico

Without seeing your models, etc...I would say that the problem is that an admin is a user so you get the home route regardless. I would restructure the if/else to first check for a logged in user like in the Laravel auth template. Then, you can check if they are also an admin.

Please sign in or create an account to participate in this conversation.