Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

Laravel how to use @auth and @guest with multi authentication

//First of all for example you can check admin guards guess like this;

@guest('admin')
    <li class="nav-item">
            <a class="nav-link" href="{{ route('auth.signin') }}">Login</a>
    </li>
    <li class="nav-item">
            <a class="nav-link" href="{{ route('auth.signup') }}">Sign Up</a>
    </li>
@endguest
  
//But i recommend this one, you can check each guard and include a partial for that guards;

@if (Auth::guard('admin')->check())
  @include('admin.auth-links')
@elseif(Auth::guard('supervisor')->check())
  @include('supervisor.auth-links')
@elseif(Auth::guard('instructor')->check())
  @include('instructor.auth-links')
@else
  @include('auth-links')
@endif

// Logout link can be single endpoint which logouts multiple guards.
 
PREVIOUS NEXT
Tagged: #Laravel #multi #authentication
ADD COMMENT
Topic
Name
4+1 =