我正在尝试建立一个没有用户管理的简单网站。
我正在使用数据库驱动程序进行缓存和会话。
我删除了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
答案 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\Kernel
(app/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,
],
],
];