2017-09-01 154 views
0

我得到這個錯誤:調用未定義的方法照亮身份驗證 TokenGuard ::嘗試()

Call to undefined method Illuminate\Auth\TokenGuard::attempt()

從這個代碼:

if(Auth::guard('admin')->attempt(['email' => $request->email, 'password' => $request->passsword], $request->remember)){ 
      return redirect()->intended(route('admin.dashboard')); 
     }else{ 

我已經進口Illuminate\Support\Facades\Authas the docs suggest

我的auth.php可能會幫助

<?php 

return [ 

    'defaults' => [ 
     'guard' => 'web', 
     'passwords' => 'users', 
    ], 
    'guards' => [ 
     'web' => [ 
      'driver' => 'session', 
      'provider' => 'users', 
     ], 
     'api' => [ 
      'driver' => 'token', 
      'provider' => 'users', 
     ], 
     'admin' => [ 
      'driver' => 'session', 
      'provider' => 'admins', 
     ], 
     'admin-api' => [ 
      'driver' => 'token', 
      'provider' => 'admins', 
     ], 
    ], 
    'providers' => [ 
     'users' => [ 
      'driver' => 'eloquent', 
      'model' => App\User::class, 
     ], 
     'admins' => [ 
      'driver' => 'eloquent', 
      'model' => App\Admin::class, 
     ], 
    ], 
    'passwords' => [ 
     'users' => [ 
      'provider' => 'users', 
      'table' => 'password_resets', 
      'expire' => 60, 
     ], 
     'admins' => [ 
      'provider' => 'admins', 
      'table' => 'password_resets', 
      'expire' => 15, 
     ], 
    ], 
]; 
+0

您的控制器中是否定義了Auth :: guard()方法?看起來它試圖使用api守衛之類的守衛,而不是你的管理員守衛。 –

回答

1

我想你可能試圖使用「會話」後衛驅動程序,而不是「令牌」。所以,試着這樣做:

配置/ auth.php配置文件:

'admin-api' => [ 
    'driver' => 'token', 
    'provider' => 'admins', 
], 

你必須將其更改爲

'admin-api' => [ 
    'driver' => 'session', 
    'provider' => 'admins', 
], 

那麼你應該運行:

  • php artisan緩存:清除
  • php手工配置:緩存

再試一次。祝你好運!

相關問題