在编译.php第1049行中的ReflectionException:类App \ Http \ Controllers \ User不存在

时间:2015-03-13 16:42:38

标签: laravel-5

我测试laravel 5我有控制器名称Usercontroller.php有代码:

  class UserController extends Controller

    {

    protected $user = null;

    public function __construct(User $user)
    {
        $this->user = $user;    
    } 

   public function allUsers()
   {
       return $this->user->allUsers();

   }    
    }

我创建模型名称user.php有代码:

class User extends Model
{
    public function allUsers()
    {
        return self::all(); 
    }

}

当我运行它时显示如下错误

ReflectionException in compiled.php line 1049: Class App\Http\Controllers\User does not exist

请帮我解决这个问题,谢谢。

1 个答案:

答案 0 :(得分:2)

User模型位于命名空间App中,您必须像这样引用它:

public function __construct(\App\User $user)
{
    $this->user = $user;    
}

或者在顶部添加一个import语句:

use App\User;

class UserController extends Controller