【问题标题】:Auth guard[] is not definedAuth guard[] 未定义
【发布时间】:2021-10-28 13:47:45
【问题描述】:

我正在使用 Laravel 8,并试图让守卫“移动”。我在网上关注了一些教程,但我不知道为什么这些教程中似乎有效的东西在我的最后不起作用。 我在互联网上搜索,我能找到的只有php artisan config:clear,但它从来没有为我工作过。

这是来自我的auth.php 文件的代码:

    <?php
    
    return [
    
    
        'defaults' => [
            'guard' => 'web',
            'passwords' => 'users',
        ],
    
       
    
        'guards' => [
            'web' => [
                'driver' => 'session',
                'provider' => 'users',
            ],
            'mobile'=> [
                'driver'=>'session',
                'provider'=>'technicians'
            ],
            'api' => [
                'driver' => 'sanctum',
                'provider' => 'users',
                'hash' => false,
            ]
        ],
    
        'providers' => [
            'users' => [
                'driver' => 'eloquent',
                'model' => App\Models\User::class,
            ],
            'technicians' => [
                'driver' => 'eloquent',
                'model' => App\Models\Technician::class,
            ]
            // 'users' => [
            //     'driver' => 'database',
            //     'table' => 'users',
            // ],
        ],
    
    
        'passwords' => [
            'users' => [
                'provider' => 'users',
                'table' => 'password_resets',
                'expire' => 60,
                'throttle' => 60,
            ],
            'technicians' => [
                'provider' => 'technicians',
                'table' => 'password_resets',
                'expire' => 60,
                'throttle' => 60
            ]
    
        ],
    
        'password_timeout' => 10800,
    
    ];

在我的控制器中,我使用这一行进行身份验证,这反过来又给了我错误:

    Auth::guard('mobile')->attempt(['email'=>'testmail@test.com',password=>'password']);

【问题讨论】:

  • 分享错误,Laravel 到底说了什么?你试过php artisan cache:clear吗?或者你可以在root-app/bootstrap/cache/*.php删除php文件
  • @MohamedGamalEldin InvalidArgumentException Auth guard [mobile] is not defined.,这是我遇到的错误
  • 您是否在 Technician 模型中扩展了 Authenticatable? use Illuminate\Foundation\Auth\User as Authenticatable; class Technician extends Authenticatable {

标签: php laravel authentication laravel-8


【解决方案1】:

我找到了错误的根源。我正在使用 phpstorm 通过 ftp 自动将文件上传到服务器。因此,我不小心将配置文件夹从正在同步的文件夹列表中排除。所以我的 auth.php 从未真正更新过。 否则代码很好

【讨论】:

    猜你喜欢
    • 2017-09-24
    • 2020-04-22
    • 2017-07-29
    • 2020-02-15
    • 2020-02-27
    • 2016-03-11
    • 2016-06-10
    • 2016-09-07
    • 1970-01-01
    相关资源
    最近更新 更多