【问题标题】:Repository class does not exist (Laravel)存储库类不存在(Laravel)
【发布时间】:2014-02-09 00:48:30
【问题描述】:

我在当前项目中使用存储库模式。当我尝试访问该路线时,我收到此错误

ReflectionException
Class Repositories\UserRepository does not exist

我的文件夹结构是这样的

- Respositories
-- UserRepository

在我的控制器中我正在做

use \Repositories\UserRepository;

class UsersController extends ApiController {

protected $user;

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

在用户存储库中

<?php namespace \Repositories

class UserRepository {

我在 composer 中自动加载

"psr-0": {
   "Respositories": "app/"
}

我的命名空间是否正确?我无法锻炼为什么找不到课程。

【问题讨论】:

  • 我不认为你打算用反斜杠作为命名空间的前缀。尝试删除它。此外,您可以省略 use 语句中的反斜杠前缀

标签: php laravel-4 psr-0


【解决方案1】:

1) 定义命名空间时不要使用前缀反斜杠。

// No
<?php namespace \Repositories;

// Yes
<?php namespace Repositories;

2) 检查您的拼写。在您的 composer.json 文件中,您有 Respositories 而不是 Repositories。

【讨论】:

    【解决方案2】:

    也许你的 laravel 没有加载你的仓库,如果这样,只需运行这个

    command composer dumpautoload
    

    如果这发生在您的部署服务器上,请阅读这篇关于此错误的文章http://www.tagipuru.xyz/2016/07/09/repository-class-does-not-exist-in-laravel/

    【讨论】:

      猜你喜欢
      • 2014-12-31
      • 2014-06-24
      • 1970-01-01
      • 2018-01-02
      • 2016-08-27
      • 2014-12-03
      • 2021-06-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多