I am using the Repository pattern in my current project. When I try and access the route I get this error

ReflectionException
Class Repositories\UserRepository does not exist

My folder structure is like so

- Respositories
-- UserRepository

In my controller I am doing

use \Repositories\UserRepository;

class UsersController extends ApiController {

protected $user;

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

In the UserRepository

<?php namespace \Repositories

class UserRepository {

I am autoloading in composer

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

Are my namespaces correct? I can not workout why it can't find the class.

有帮助吗?

解决方案

1) Don't use prefixed back slashes when defining the namespace.

// No
<?php namespace \Repositories;

// Yes
<?php namespace Repositories;

2) Check your spelling. In your composer.json file, you have Respositories instead of Repositories.

其他提示

maybe your laravel hasn't load your repository, if thus, just simply run this

command composer dumpautoload

if this occurred on your deployment server, have read this article regarding on this error http://www.tagipuru.xyz/2016/07/09/repository-class-does-not-exist-in-laravel/

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top