joshuahornby10 joshuahornby10 - 3 months ago 12x
PHP Question

Repository class does not exist (Laravel)

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

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.