未定义的属性:Illuminate\Auth\SessionGuard::$Auth(在 laravel 7.30.4 中)

Posted

技术标签:

【中文标题】未定义的属性:Illuminate\\Auth\\SessionGuard::$Auth(在 laravel 7.30.4 中)【英文标题】:Undefined property: Illuminate\Auth\SessionGuard::$Auth (In laravel 7.30.4)未定义的属性:Illuminate\Auth\SessionGuard::$Auth(在 laravel 7.30.4 中) 【发布时间】:2021-07-04 16:07:57 【问题描述】:

试图建立一个多重身份验证系统。管理员的索引页面未打开,出现上述错误消息。 Admin Login Controller

Web.php

Admin Controller

Error Message

现在我想在系统中有两个用户。 Auth.php 的代码如下:

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

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

    'madmin' => [
        'driver' => 'session',
        'provider' => 'madmins',
    ],
],

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

    // 'users' => [
    //     'driver' => 'database',
    //     'table' => 'users',
    // ],

    'madmins' => [
        'driver' => 'eloquent',
        'model' => App\Madmin::class,
    ],
],


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

    'madmins' => [
        'provider' => 'madmins',
        'table' => 'password_resets',
        'expire' => 60,
        'throttle' => 60,
    ],
],

【问题讨论】:

请添加实际代码,而不仅仅是图片。 【参考方案1】:

我认为您必须像这样删除第二个 Auth

if(Auth::guard('madmin')->attempt())

然后继续你的代码

【讨论】:

我这样做并收到错误消息“未定义的方法尝试” 你能给我看看config目录下的auth.php文件吗? 我附加了 auth.php 文件并尝试了上述方法,但收到错误消息“未定义方法'尝试'.intelephense(1013)”

以上是关于未定义的属性:Illuminate\Auth\SessionGuard::$Auth(在 laravel 7.30.4 中)的主要内容,如果未能解决你的问题,请参考以下文章

无法读取未定义类型错误的属性“推送”:无法读取未定义错误的属性“推送”

带有 Ionic 4 的 SQLite?无法读取未定义类型错误的属性“then”:无法读取未定义的属性“then”

NextJS:未捕获的类型错误:无法读取未定义的属性(读取“属性”)

为啥 Firebug 不为未定义的属性显示“未捕获的类型错误”?

未捕获的类型错误:无法读取未定义的属性“区域”?

js运行错误 无法获取未定义或 null 引用的属性“pagecount”