【问题标题】:Laravel reset password, Class '\App\User' not foundLaravel 重置密码,找不到类 '\App\User'
【发布时间】:2016-01-23 07:30:49
【问题描述】:

我正在尝试创建一个重置密码 URI,它在那里并使用 Laravel 内置的重置密码系统,但是当我测试它时,我得到:

EloquentUserProvider.php 第 126 行中的 FatalErrorException:类 '\App\User' 未找到

这是我的配置/auth.php:

/*
|--------------------------------------------------------------------------
| Authentication Model
|--------------------------------------------------------------------------
|
| When using the "Eloquent" authentication driver, we need to know which
| Eloquent model should be used to retrieve your users. Of course, it
| is often just the "User" model but you may use whatever you like.
|
*/

'model' => App\User::class,

这是我的 app/Http/routes.php:

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::post('register', 'RegisterController@register');

Route::post('resetpassword', 'Auth\PasswordController@postEmail');

Route::resource('api/authenticate', 'AuthenticateController', ['only' => ['index']]);
Route::post('api/authenticate', 'AuthenticateController@authenticate');

//All protected routes should go in this group
Route::group(['middleware' => 'isUserAuthed'], function () {
  Route::get('restricted', 'WelcomeController@welcome');
});

我的用户类位于 app/User.php:

<?php

namespace App;

use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class User extends Model implements AuthenticatableContract,
                                AuthorizableContract,
                                CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword;

/**
 * The database table used by the model.
 *
 * @var string
 */
protected $table = 'users';

/**
 * The attributes that are mass assignable.
 *
 * @var array
 */
protected $fillable = ['name', 'username', 'password', 'role', 'active', 'email'];

/**
 * The attributes excluded from the model's JSON form.
 *
 * @var array
 */
protected $hidden = ['password', 'remember_token'];
}

有人能指出我正确的方向吗?这方面的文档对我来说似乎不是很清楚。

【问题讨论】:

  • 嗯,您是否将默认的User 模型移到了其他地方?默认情况下,它就在app 目录下。
  • 你在app/User.php有什么?
  • 我已将其添加到上述问题中。它位于 app/User.php。

标签: php laravel


【解决方案1】:

你的文件名应该是User.php 而不是user.php

【讨论】:

  • 哦,对不起,是app/User.php。现在已经在问题中更新了。
【解决方案2】:

\App\User 应该可以被 EloquentUserProvider 找到

您是否尝试过在您的应用程序文件夹中运行此命令?

composer dump-autoload

【讨论】:

  • 我刚刚这样做了,它给出了同样的错误:找不到类'\App\User'
【解决方案3】:

尝试删除::class

'model' => 'App\User',

【讨论】:

  • 我之前也尝试过。但我收到此错误:[Sat Oct 24 23:30:15 2015] [error] [client 24.10.139.15] PHP Fatal error: Undefined constant 'App\\User' in /home/ct.1.1/config/auth.php on line 31
  • 你可能忘记了单引号。
  • 这应该不是问题。该错误表明 \App\User 类不存在。并不是说::class有什么问题。
猜你喜欢
  • 2021-12-28
  • 2017-06-07
  • 2017-10-04
  • 2019-10-17
  • 1970-01-01
  • 1970-01-01
  • 2021-08-31
  • 2021-01-08
  • 1970-01-01
相关资源
最近更新 更多