我在Laravel 5.5中有一个多身份验证系统设置(使用Hesto软件包的自定义版本),除了这一个细节外,一切都正常。在“welcome.php”登录页面上,导航栏应显示登录状态和授权用户类型的不同链接。
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')
我认为下面的语法是正确的,但是在@else语句之后我遇到了问题。案例1根本没有显示链接,也没有错误响应。
@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
我已经尝试了上述代码的几个重组/重新配置的版本无济于事。大多数抛出语法错误。如有必要,我可举例。我知道我错过了一些非常简单的事情,但是现在已经把我的头撞到了墙上太多次,以便有希望自己找到它。
提前非常感谢。如果您需要我的代码中的任何其他部分,请告诉我。
配置/ 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, ], ],
答案 0 :(得分:0)
今天下午坐下来工作,检查相关的外墙。我的语法是一个简单的错误,我说得对。从那时起就一直踢着自己。
如果它对任何人都有用......
我有多个警卫处于活动状态以启用&#34;用户&#34;,&#34;客户&#34;和&#34;管理员&#34;我的应用程序需要的模型。在这种情况下,我需要调用auth facade的guard方法然后 - > gt; check()对每个单独调用。见下文:
@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