php Laravel 说未定义 Auth guard []

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34116211/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:45:34  来源:igfitidea点击:

Laravel say that Auth guard [] is not defined

phplaravelauthenticationrouteslaravel-5.1

提问by MonkeyBusiness

I'm beginer and I start learn and code with laravel... To enable user login nad registration I write this (as I see on one tutorilal):

我是初学者,我开始学习和使用 laravel 编写代码......为了启用用户登录和注册,我写了这个(正如我在一个教程中看到的那样)

at routes.php

在routes.php

 Route::controllers([
     'auth'=>'Auth\AuthController',
     'password'=>'Auth\PasswordController', ]);

and now when I type: http://localhost:8888/auth/loginI get error:

现在当我输入:http://localhost:8888/auth/login我得到错误:

InvalidArgumentException in AuthManager.php line 71: Auth guard [] is not defined.

InvalidArgumentException in AuthManager.php line 71: Auth guard [] 未定义。

enter image description here

在此处输入图片说明

Also in view folder there is no auth directory and login.blade.php files and other.

同样在视图文件夹中没有 auth 目录和 login.blade.php 文件等。

回答by Matt

Make sure that your config/auth.php is updated if you've upgraded from 5.1.x to 5.2.

如果您已从 5.1.x 升级到 5.2,请确保您的 config/auth.php 已更新。

https://github.com/laravel/laravel/blob/v5.2.0/config/auth.php

https://github.com/laravel/laravel/blob/v5.2.0/config/auth.php

回答by Jason Tumusiime

In case you edited your config/auth.php, e.g. to add another guard and your config is cached, your guards may not be reloaded. If you experience this problem, clearing the config will fix it.

如果你编辑了你的config/auth.php,例如添加另一个守卫并且你的配置被缓存,你的守卫可能不会重新加载。如果您遇到此问题,清除配置将修复它。

$php artisan config:clearor $php artisan config:cache

$php artisan config:clear或者 $php artisan config:cache

I'm using laravel 5.5

我正在使用 Laravel 5.5

回答by HoLiC

This could be a problem in your config/auth.php file, where the 'defaults' array is setting a non-existing guard on Laravel 5.2.

这可能是您的 config/auth.php 文件中的问题,其中 'defaults' 数组在 Laravel 5.2 上设置了一个不存在的保护。

回答by sachinsuthariya

program directory App/config/Auth.php

程序目录 App/config/Auth.php

<?php
 return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
    'guard' => 'web',
    'passwords' => 'users',
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session", "token"
|
*/
'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],
    'api' => [
        'driver' => 'token',
        'provider' => 'users',
    ],

   // define your Auth here..

   'your_auth_name' => [
        'driver' => 'session',
        'provider' => 'your table name',
    ],

],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\User::class,
    ],
    // 'users' => [
    //     'driver' => 'database',
    //     'table' => 'users',
    // ],

    // add provider to your auth
       'table name' => [
        'driver' => 'eloquent',
        'model' => App\User::class,
    ],
   // **'model' => App\User::class,**
  // here App\User is model so you have to generate own model using **php artisan make:model Model_name**


],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| Here you may set the options for resetting passwords including the view
| that is your password reset e-mail. You may also set the name of the
| table that maintains all of the reset tokens for your application.
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
    'users' => [
        'provider' => 'users',
        'email' => 'auth.emails.password',
        'table' => 'password_resets',
        'expire' => 60,
    ],
], ];