【问题标题】:Illuminate\Auth\SessionGuard::__construct() must implement interfaceIlluminate\Auth\SessionGuard::__construct() 必须实现接口
【发布时间】:2019-09-13 23:20:39
【问题描述】:

我已经阅读了有关我的错误的其他问题,因此我重新检查了我的代码并没有发现任何拼写错误, 错误

Symfony\Component\Debug\Exception\FatalThrowableError (E_RECOVERABLE_ERROR) 参数 2 传递给 Illuminate\Auth\SessionGuard::__construct() 必须实现接口 Illuminate\Contracts\Auth\UserProvider,给定 null,调用 \vendor\laravel\framework\src\Illuminate\Auth\AuthManager.php 上线 125

Auth.php

return [

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

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

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

        'admin' => [
            'driver' => 'session',
            'provider' => 'admin',
        ],

        'user' => [
            'driver' => 'session',
            'provider' => 'user',
        ],

        'company' => [
            'driver' => 'session',
            'provider' => 'company',
        ],

        'employee' => [
            'driver' => 'session',
            'provider' => 'employee',
        ],
    ],



    'providers' => [

        'admin' => [
            'driver' => 'eloquent',
            'model' => App\Admin::class,
        ],

        'company' => [
            'driver' => 'eloquent',
            'model' => App\Model\Employee::class,
        ],

        'employee' => [
            'driver' => 'eloquent',
            'model' => App\Model\Employee::class,
        ],

    ],

];

【问题讨论】:

  • 有什么问题?
  • @morph 读取问题的第二段,我在多重身份验证时遇到错误。

标签: laravel authentication laravel-5.8


【解决方案1】:

你需要为你的新守卫定义提供者,否则它会抛出错误。当您引用 admins

的特定迁移表时,您的提供商也应拼写为 'admins'
'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\User::class,
    ],


    'admins' => [
        'driver' => 'eloquent',
        'model' => App\Admin::class,
    ],
],

【讨论】:

    【解决方案2】:

    一切都很好我只是在控制器中被称为旧默认用户身份验证,我在旧项目中进行了修改,现在我安装了新项目,然后移动除了 user.php 默认模型之外的所有文件

     $companyAuth = auth()->guard('user'); //called wrong default 
     $companyAuth = auth()->guard('employee'); //now working fine
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-11
      • 2021-12-22
      • 1970-01-01
      • 2020-02-04
      • 2020-01-13
      • 2013-10-03
      • 2021-10-19
      相关资源
      最近更新 更多