![](/img/trans.png)
[英]Argument 2 passed to Arubacao\BasicAuth\BasicGuard::__construct() must be an instance of Illuminate\Contracts\Auth\UserProvider, null given
[英]Laravel 8 : Argument 2 passed to Illuminate\Auth\SessionGuard::__construct() must be an instance of Illuminate\Contracts\Auth\UserProvider, null given
我正在嘗試為我的應用程序的用戶和管理員創建多重保護身份驗證。 在將其標記為重復或其他內容之前,請閱讀它並讓別人幫助我。 我已經嘗試了來自相同問題解決方案的所有可能解決方案,但直到現在都沒有奏效。
這是我的代碼:
授權.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
'admin' => [
'driver' => 'session',
'providers' => 'admins'
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
'admins' => [
'driver' => 'eloquent',
'model' => App\Models\AdminUser::class,
],
],
AdminUser.php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Model;
class AdminUser extends Authenticatable
{
use HasFactory, Notifiable;
protected $table = 'admin_users';
protected $guard = 'admin';
protected $fillable = [
'first_name',
'middle_name',
'last_name',
'email',
'password',
];
protected $hidden = [
'password',
'remember_token',
];
protected $casts = [
'email_verified_at' => 'datetime',
];
}
AdminAuthController.php
class AdminAuthController extends Controller {
public function __construct()
{
$this->middleware('auth:admin');
}
public function getLogin()
{
return view('login');
}
}
web.php
Route::get('/login', 'LoginController@index')->name('login');
Route::get('/admin/login','AdminAuthController@getLogin');
當我 go 到我的應用程序/登錄時,它要求輸入用戶名和密碼,並在通過身份驗證后讓我進入。 但是當我 go 到my-application/admin/login時,它給了我這個錯誤:
傳遞給 Illuminate\Auth\SessionGuard::__construct() 的參數 2 必須是 Illuminate\Contracts\Auth\UserProvider 的實例,給定 null,在 /var/www/vhosts/my-application/httpdocs/vendor/laravel/framework 中調用/src/Illuminate/Auth/AuthManager.php 第 124 行
我嘗試了相同問題的解決方案,但沒有任何幫助。Laravel 文檔有點混亂,所以我在這里尋求您的幫助。 請幫助我,我提前感謝你的幫助。 我正在使用 Laravel 8.*
我昨天才遇到這個問題。 我對 web 開發比較陌生。 原來問題出在我的 cofig/auth.php 上。 在設置“守衛”部分時,我將提供程序設置為引用表名 ('provider' => 'admins_user') 而不是它下面的“提供程序”部分 ('provider' => 'admins')。 解決方案:當我將守衛指向“提供者”部分時,它已解決。 我知道這對我來說是一個愚蠢的錯誤,但我希望這能幫助有類似情況的人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.