多个身份验证时出错

时间:2018-04-16 18:00:58

标签: laravel laravel-5.6

我尝试创建多个身份验证,但每次我都会:

  

类型错误:传递给Illuminate \ Auth \ SessionGuard :: __ construct()的参数2必须是Illuminate \ Contracts \ Auth \ UserProvider的一个实例,给定null,在/ Users / admin / www / laravelapp / vendor / laravel中调用第123行/framework/src/Illuminate/Auth/AuthManager.php

在谷歌搜索但没有任何帮助。不知道。可能有人之前有这个错误?我的auth.php在config中:

<?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,
    ],
    'admin' => [
        'driver' => 'eloquent',
        'model' => App\Admin::class,
    ],
],
   ...

清除缓存。但没有帮助。 PS:我之前在另一个项目中使用过它,但没有在新项目中使用过。 :/

1 个答案:

答案 0 :(得分:1)

天啊,我发现了问题。问题:提供商名称错误:/

'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' => [ //<----- changed to admins like in guards 
        'driver' => 'eloquent',
        'model' => App\Admin::class,
    ],
],
   ...

有时您需要将代码发布到stackoverflow以查看您自己的问题:)