简体   繁体   English

Laravel 8:传递给 Illuminate\Auth\SessionGuard::__construct() 的参数 2 必须是 Illuminate\Contracts\Auth\UserProvider 的实例,null 给定

[英]Laravel 8 : Argument 2 passed to Illuminate\Auth\SessionGuard::__construct() must be an instance of Illuminate\Contracts\Auth\UserProvider, null given

I am trying to create multiple guard authentication for Users and Admins for my application.我正在尝试为我的应用程序的用户和管理员创建多重保护身份验证。 Before you mark it as duplicate or something, please read it and let someone help me.在将其标记为重复或其他内容之前,请阅读它并让别人帮助我。 I have tried all the possible solutions from same issues solutions but nothing worked till now.我已经尝试了来自相同问题解决方案的所有可能解决方案,但直到现在都没有奏效。

Here is my code:这是我的代码:

auth.php授权.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 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 AdminAuthController.php

class AdminAuthController extends Controller {
    public function __construct()
    {
        $this->middleware('auth:admin');
    }

    public function getLogin()
    {
        return view('login');
    } 
}

web.php web.php

Route::get('/login', 'LoginController@index')->name('login');
Route::get('/admin/login','AdminAuthController@getLogin');

When I go to my-application/login it ask for username and password and let me in once authenticated.当我 go 到我的应用程序/登录时,它要求输入用户名和密码,并在通过身份验证后让我进入。 But when I go to my-application/admin/login , it gives me this error:但是当我 go 到my-application/admin/login时,它给了我这个错误:

Argument 2 passed to Illuminate\Auth\SessionGuard::__construct() must be an instance of Illuminate\Contracts\Auth\UserProvider, null given, called in /var/www/vhosts/my-application/httpdocs/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php on line 124传递给 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 行

I tried solutions with the same issue, but nothing helped.Laravel documentation is bit confusing and so I am here to seek your help.我尝试了相同问题的解决方案,但没有任何帮助。Laravel 文档有点混乱,所以我在这里寻求您的帮助。 Please help me out and I appreciate your help in advance.请帮助我,我提前感谢你的帮助。 I am using Laravel 8.*我正在使用 Laravel 8.*

I faced this issue just yesterday.我昨天才遇到这个问题。 I am relatively new to web development.我对 web 开发比较陌生。 It turned out the issue arose from my cofig/auth.php.原来问题出在我的 cofig/auth.php 上。 In setting the "guards" section, I set the provider to reference the table name ('provider' => 'admins_user') rather than the "providers" section below it ('provider' => 'admins').在设置“守卫”部分时,我将提供程序设置为引用表名 ('provider' => 'admins_user') 而不是它下面的“提供程序”部分 ('provider' => 'admins')。 Solution: When I pointed guards to the "providers" section, it was resolved.解决方案:当我将守卫指向“提供者”部分时,它已解决。 I know it's a silly mistake on my side but I hope this helps someone out there with similar circumstances.我知道这对我来说是一个愚蠢的错误,但我希望这能帮助有类似情况的人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 传递给 Arubaao\\BasicAuth\\BasicGuard::__construct() 的参数 2 必须是 Illuminate\\Contracts\\Auth\\UserProvider 的实例,给定 null - Argument 2 passed to Arubacao\BasicAuth\BasicGuard::__construct() must be an instance of Illuminate\Contracts\Auth\UserProvider, null given 社交名流:传递给 Illuminate\Auth\SessionGuard::login() 的参数 1 必须实现接口 Illuminate\Contracts\Auth\Authenticatable,给定 null - Socialite : Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, null given LARAVEL 7.0 传递给 Illuminate\\Auth\\SessionGuard::login() 的参数 1 必须实现接口 Illuminate\\Contracts\\Auth\\Authenticatable,给定数组 - LARAVEL 7.0 Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, array given Laravel Messenger-传递给Illuminate \\ Auth \\ Guard :: login()的参数1必须实现Illuminate \\ Contracts \\ Auth \\ Authenticatable接口,给定null - Laravel messenger - Argument 1 passed to Illuminate\Auth\Guard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, null given 传递给 Illuminate\Auth\EloquentUserProvider::validateCredentials() 的参数 1 必须是 Illuminate\Contracts\Auth\Authenticatable 的实例 - Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Contracts\Auth\Authenticatable 注册错误,参数1传递给laravel 5.8中的Illuminate \\ Auth \\ SessionGuard :: login() - Registration error, Argument 1 passed to Illuminate\Auth\SessionGuard::login() in laravel 5.8 TypeError: Illuminate\Auth\SessionGuard::login(): 参数 #1 ($user) 必须是类型 Illuminate\Contracts\Auth\Authenticatable,, App\Models\Admin giv - TypeError: Illuminate\Auth\SessionGuard::login(): Argument #1 ($user) must be of type Illuminate\Contracts\Auth\Authenticatable,, App\Models\Admin giv 问题:参数 #1 ($user) 必须是 Illuminate\Contracts\Auth\Authenticatable 类型,null 给定,调用 - Issue: Argument #1 ($user) must be of type Illuminate\Contracts\Auth\Authenticatable, null given, called in Illuminate\Auth\SessionGuard::login(): 参数 #1 ($user) 必须是类型 - Illuminate\Auth\SessionGuard::login(): Argument #1 ($user) must be of type 在laravel 5.8注册期间添加ROLE时,参数1传递给Illuminate \\ Auth \\ SessionGuard :: login() - Argument 1 passed to Illuminate\Auth\SessionGuard::login() when adding ROLE during registration in laravel 5.8
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM