Laravel:未定义身份验证用户提供程序[]

时间:2018-01-10 14:31:50

标签: laravel laravel-5 laravel-5.5

我正在尝试建立一个没有用户管理的简单网站。

我正在使用数据库驱动程序进行缓存和会话。

我删除了Laravel附带的所有与用户相关的样板代码,但我一直在标题中收到错误消息。

这是我的config/auth.php

return [

    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],
    ],

    'providers' => [
        'users' => [],
    ],

    'passwords' => [
        'users' => [],
    ],

];

如果有人打算不在他的网站上支持用户,是否可以没有定义用户提供商?

编辑1 :禁用Illuminate\Auth\AuthServiceProvider服务提供商后,我收到以下异常:

ReflectionException thrown with message "Class auth.driver does not exist"

> Stacktrace:
> #16 ReflectionException in vendor\laravel\framework\src\Illuminate\Container\Container.php:752
> #15 ReflectionClass:__construct in vendor\laravel\framework\src\Illuminate\Container\Container.php:752
> #14 Illuminate\Container\Container:build in vendor\laravel\framework\src\Illuminate\Container\Container.php:631
> #13 Illuminate\Container\Container:resolve in vendor\laravel\framework\src\Illuminate\Container\Container.php:586
> #12 Illuminate\Container\Container:make in vendor\laravel\framework\src\Illuminate\Foundation\Application.php:732
> #11 Illuminate\Foundation\Application:make in vendor\laravel\framework\src\Illuminate\Session\DatabaseSessionHandler.php:213
> #10 Illuminate\Session\DatabaseSessionHandler:userId in vendor\laravel\framework\src\Illuminate\Session\DatabaseSessionHandler.php:200
> #9 Illuminate\Session\DatabaseSessionHandler:addUserInformation in vendor\laravel\framework\src\Illuminate\Session\DatabaseSessionHandler.php:186
> #8 Illuminate\Session\DatabaseSessionHandler:Illuminate\Session\{closure}
> in vendor\laravel\framework\src\Illuminate\Support\helpers.php:1035
> #7 tap in vendor\laravel\framework\src\Illuminate\Session\DatabaseSessionHandler.php:188
> #6 Illuminate\Session\DatabaseSessionHandler:getDefaultPayload in vendor\laravel\framework\src\Illuminate\Session\DatabaseSessionHandler.php:125
> #5 Illuminate\Session\DatabaseSessionHandler:write in vendor\laravel\framework\src\Illuminate\Session\Store.php:128
> #4 Illuminate\Session\Store:save in vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php:87
> #3 Illuminate\Session\Middleware\StartSession:terminate in vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:218
> #2 Illuminate\Foundation\Http\Kernel:terminateMiddleware in vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:189
> #1 Illuminate\Foundation\Http\Kernel:terminate in public\index.php:60
> #0 require_once in server.php:21

3 个答案:

答案 0 :(得分:1)

您可能需要在AuthServiceProvider中注释掉config/app.php

'providers' => [

    /*
     * Laravel Framework Service Providers...
     */
    Illuminate\Auth\AuthServiceProvider::class,  // COMMENT THIS OUT

如果您发布整个堆栈跟踪,我们可以确认此错误的来源

答案 1 :(得分:0)

如果您要完全从Larvel安装中删除Auth,则需要做几件事。

config/app.php中删除以下内容:

主要身份验证服务提供商,通常是第一项。

Illuminate\Auth\AuthServiceProvider::class

您的特定于应用程序的身份验证服务提供商(在第169行附近)。

App\Providers\AuthServiceProvider::class

然后,您要转到App\Http\Kernelapp/Http/Kernel.php)并删除所有与身份验证有关的中间件。

通常将其注释掉,但还是要删除($middlewareGroups中第34行附近)

// \Illuminate\Session\Middleware\AuthenticateSession::class,

下一步,删除$routeMiddleware中的别名

'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,

下一步,删除$middlewarePriority

中的条目
\App\Http\Middleware\Authenticate::class
\Illuminate\Session\Middleware\AuthenticateSession::class

\Illuminate\Auth\Middleware\Authorize::class

然后最后,删除app/Http/Middleware/Authenticate.php

不幸的是,由于根深蒂固,无法完全删除身份验证库,但这实际上将禁用它。只要您不调用任何基于身份验证的功能,就可以了。

答案 2 :(得分:0)

return [

    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],


    'guards' => [
        'web' => [ //Laravel default guard name
            'driver' => 'session', 
            'provider' => 'users', // Laravel authenticate table/model name
        ],

        'admin' => [  //Our Custom guard name "admin"
            'driver' => 'session',  
            'provider' => 'admins',  // Our authenticate table/model name
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],


    ],

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class, //Laravel guard model slug
        ],

        'admins' => [  
            'driver' => 'eloquent',  //Our custom eloquent
            'model' => App\Model\Admin\Admin::class, //Our custom guard model slug
        ],
    ],

    'passwords' => [
        'users' => [
            'provider' => 'users',
            'table' => 'password_resets',
            'expire' => 60,
        ],

        'admins' => [  // And here also
            'provider' => 'admins',
            'table' => 'password_resets',
            'expire' => 60,
        ],
    ],

];