under5hell
under5hell

Reputation: 997

Laravel ReflectionException error : Repository doesn't exist

I know this question lil bit old, but i still can't find the right solution. I've been search the internet for days, and try several solutions, check my files path, update the composer.json and and dump-autoload it, but still no luck. I still get the following error :

ReflectionException
Class Cribbb\Storage\User\EUserRepository does not exist

here's my code.

The controller (app/controllers/UsersControllers.php) :

<?php

use Cribbb\Storage\User\IUserRepository as User; 

class UsersController extends \BaseController {

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */

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

The interface (lib/Cribbb/Storage/User/IUserRepository.php) :

<?php

namespace Cribbb\Storage\User;

interface IUserRepository{

    public function all();
    public function find($id);  
    public function create($input);
}

?>

The Repository (lib/Cribbb/Storage/User/EUserRepository.php) :

<?php

namepsace Cribbb\Storage\User;

use User;

class EUserRepository implements IUserRepository
{

    public function all()
    {
        return User::all(); 
    }

    public function find($id)
    {
        return User::find($id);
    }

    public function create($input)
    {
        return User::create($input);
    }



} 

?>

The Service Provider (lib/Cribbb/Storage/StorageServiceProvider.php) :

<?php

namespace Cribbb\Storage;

use Illuminate\Support\ServiceProvider;

class StorageServiceProvider extends ServiceProvider {

  public function register()
  {
    $this->app->bind(
      'Cribbb\Storage\User\IUserRepository',
      'Cribbb\Storage\User\EUserRepository'
    );
  }

} ?>

i also included the service provider in app/config/app.php as follow :

'providers' => array(
...
'Cribbb\Storage\StorageServiceProvider'
);

and i added app/lib the composer.json :

"autoload": {
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/models",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php",
            "app/lib"
        ]
    }

The odd part about this is, while IUserRepository and EUserRepository is in the same folder, Laravel only detect the IUserRepository. It seems cannot find the EUserRepository. Do I miss something important? any advice guys?

Upvotes: 0

Views: 2031

Answers (1)

veelasky
veelasky

Reputation: 334

namepsace Cribbb\Storage\User;

should it be namespace?

EDIT

The Repository (lib/Cribbb/Storage/User/EUserRepository.php) has a typo:

<?php

namepsace Cribbb\Storage\User;

Because you didn't use autoloading it just loads as \EUserRepository class. (root scope)

Upvotes: 3

Related Questions