1
我有以下文件:Laravel 5.4中間件不能定義後衛
routes.php文件
Route::get('client-portal', '[email protected]');
DashboardController.php
public function __construct()
{
$this->middleware('auth:client-users');
}
auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'client-users' => [
'driver' => 'session',
'provider' => 'client-users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'client-users' => [
'driver' => 'eloquent',
'model' => \App\Models\ClientPortal\User::class
],
],
Authenticate.php
public function __construct(Guard $auth) {
$this->auth = $auth;
}
public function handle($request, Closure $next)
{
if ($this->auth->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
dd($this->auth);
return redirect()->guest('login');
}
}
return $next($request);
}
每當我通過client-users
登錄並瀏覽到/client-portal.
從Authenticate.php
的dd
返回一個SessionGuard
實例,與屬性name
設置爲web
但是,我並指定「身份驗證:客戶端用戶在控制器的構造函數中。 所以我的第一個想法是認證中間件是全球中間件,所以我檢查了它,但事實並非如此。如果我從構造函數中刪除中間件行,則會顯示頁面。
有誰知道問題在哪裏?
謝謝。