Laravel ReflectionException错误:存储库不存在 [英] Laravel ReflectionException error : Repository doesn't exist
问题描述
我知道这个问题有点老,但是我仍然找不到正确的解决方案.我已经在互联网上搜索了几天,并尝试了几种解决方案,检查了我的文件路径,更新了composer.json并转储自动加载它,但是还是没有运气.我仍然收到以下错误:
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
这是我的代码.
控制器(app/controllers/UsersControllers.php):
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;
}
?>
接口(lib/Cribbb/Storage/User/IUserRepository.php):
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);
}
?>
存储库(lib/Cribbb/Storage/User/EUserRepository.php):
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);
}
}
?>
服务提供者(lib/Cribbb/Storage/StorageServiceProvider.php):
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'
);
}
} ?>
我还将服务提供商包含在app/config/app.php中,如下所示:
i also included the service provider in app/config/app.php as follow :
'providers' => array(
...
'Cribbb\Storage\StorageServiceProvider'
);
并且我添加了app/lib composer.json:
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"
]
}
奇怪的是,虽然IUserRepository和EUserRepository在同一文件夹中,但Laravel仅检测IUserRepository.似乎找不到EUserRepository. 我会错过重要的事情吗?有什么建议吗?
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?
推荐答案
namepsace Cribbb\Storage\User;
应该是名称空间吗?
编辑
存储库(lib/Cribbb/Storage/User/EUserRepository.php)有一个错字:
The Repository (lib/Cribbb/Storage/User/EUserRepository.php) has a typo:
<?php
namepsace Cribbb\Storage\User;
因为您没有使用自动加载功能,所以它只是作为\EUserRepository
类加载. (根范围)
Because you didn't use autoloading it just loads as \EUserRepository
class. (root scope)
这篇关于Laravel ReflectionException错误:存储库不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!