我是初学者,我开始用laravel学习和编写代码...... 要启用用户登录nad注册,我写这个(正如我在一个tutorilal上看到的那样):
在routes.php
Route::controllers([
'auth'=>'Auth\AuthController',
'password'=>'Auth\PasswordController', ]);
现在当我输入:http://localhost:8888/auth/login时出现错误:
AuthManager.php第71行中的InvalidArgumentException: Auth guard []是 没有定义。
同样在view文件夹中,没有auth目录和login.blade.php文件等。
答案 0 :(得分:17)
如果您已从5.1.x升级到5.2,请确保更新config / auth.php。
https://github.com/laravel/laravel/blob/v5.2.0/config/auth.php
答案 1 :(得分:5)
如果您修改了config/auth.php
,例如要添加另一个警卫并且您的配置已缓存,您的警卫可能无法重新加载。如果您遇到此问题,清除配置将修复它。
$php artisan config:clear
或$php artisan config:cache
我正在使用laravel 5.5
答案 2 :(得分:3)
这可能是您的config / auth.php文件中的问题,其中'默认' array正在Laravel 5.2上设置一个不存在的防护。
答案 3 :(得分:0)
程序目录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,
],
], ];
答案 4 :(得分:0)
此问题的主要原因是您的系统无法检测到新创建的守卫。 就跑
php artisan config:clear
php artisan config:cache
如果您无法在共享主机中运行以上 artisan 命令或项目,请将以下代码写入您的 web.php 文件
Route::get('/clear', function() {
Artisan::call('cache:clear');
Artisan::call('config:clear');
Artisan::call('config:cache');
Artisan::call('view:clear');
Artisan::call('route:clear');
return "Cleared!";
});
现在,在您的基本网址后面写上“清除”并按回车键。希望您的问题能解决。