0

I have a multi-auth system setup (using a custom version of the Hesto package) within Laravel 5.5, and everything is working just as I like except for this one detail. On the "welcome.php" landing page, the navbar should show different links respective of login status, and authorized user-type.

 case 1: -User is not logged in, and should see two auth links: 1) User login 2) Client login case 2: -User is logged in as a "user", and should only see a link for their dashboard ('/user/dashboard') case 3: -User is logged in as a "client", and should only see a link for their respective dashboard ('/client/dashboard') 

I thought my syntax below would be correct, but I'm having an issue after the @else statement. Case 1 shows no links at all, and no error response.

@if (Route::has('login')) // Check 'user' guard @auth('user') <a class="nav-item nav-link theme-faded-bg-light" href="{{ url('/user/dashboard') }}">Dashboard</a> @endauth // Check 'client' guard @auth('client') <a class="nav-item nav-link theme-faded-bg-light" href="{{ url('/client/dashboard') }}">Dashboard</a> @endauth @else <a class="nav-item nav-link theme-faded-bg-light" href="{{ route('user-login') }}">Firm Login</a> <a class="nav-item nav-link theme-faded-bg-light" href="{{ route('client-login') }}">Client Login</a> @endif 

I've tried several reorganized/reformulated version of the above code to no avail. Most throw syntax errors. I can give examples if necessary. I know I'm missing something very simple but have bashed my head against the wall too many times now to have any hope of finding it on my own.

Thanks so much in advance. Let me know if you need any other bits of my code.

config/auth.php

 'defaults' => [ 'guard' => 'web', 'passwords' => 'users', ], // Guards 'guards' => [ 'client' => [ 'driver' => 'session', 'provider' => 'clients', ], 'user' => [ 'driver' => 'session', 'provider' => 'users', ], 'admin' => [ 'driver' => 'session', 'provider' => 'admins', ], 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [ 'driver' => 'token', 'provider' => 'users', ], ], // Providers 'providers' => [ 'clients' => [ 'driver' => 'eloquent', 'model' => App\Client::class, ], 'admins' => [ 'driver' => 'eloquent', 'model' => App\Admin::class, ], 'users' => [ 'driver' => 'eloquent', 'model' => App\User::class, ], ], 

debug toolbar screenshot

4
  • Please tell us the current error running the current version of the code! Commented Oct 14, 2017 at 21:59
  • So you see no links - right? Can you add the guard-codes to see if there is something wrong? Do you use laravel-debug-toolbar and can screenshot the "auth"-tab? Commented Oct 14, 2017 at 22:05
  • Correct, no links. I don't use the laravel-debug-toolbar, but I'll install it and see if it helps me work it out. I'll add the guard codes to my question in just a moment. Commented Oct 14, 2017 at 22:09
  • I've provided my config/auth.php file. If there is another file that would be helpful, please specify and I'll add it, as well. Commented Oct 14, 2017 at 22:21

1 Answer 1

0

Sat back down to work at it this afternoon and checked the relevant facades. I was right about it being a simple error in my syntax. Been kicking myself ever since.

In case it comes of use to anyone else...

I have multiple guards active to enable the "User", "Client", and "Admin" models needed by my app. In this case, I need to call on the guard method of the auth facade and then ->check() against each individually. See below:

@if(Auth::guard('user')->check()) <a class="nav-item nav-link theme-faded-bg-light" href="{{ route('user.dashboard') }}">Dashboard</a> @elseif(Auth::guard('client')->check()) <a class="nav-item nav-link theme-faded-bg-light" href="{{ route('client.dash') }}">Dashboard</a> @else <a class="nav-item nav-link theme-faded-bg-light" href="/user/login">Firm Login</a> <a class="nav-item nav-link theme-faded-bg-light" href="{{ route('client-login') }}">Client Login</a> @endif 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.