我知道這個問題lil有點舊,但我仍然找不到合適的解決方案。我一直在搜索互聯網幾天,並嘗試幾種解決方案,檢查我的文件路徑,更新composer.json,然後dump-autoload它,但仍然沒有運氣。我仍然收到以下錯誤:Laravel ReflectionException錯誤:庫不存在
ReflectionException
Class Cribbb\Storage\User\EUserRepository does not exist
這是我的代碼。
控制器(應用程序/控制器/ 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 /存儲/用戶/ 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):
<?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 /存儲/ StorageServiceProv ider.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.php如下服務提供商:
'providers' => array(
...
'Cribbb\Storage\StorageServiceProvider'
);
和我添加的應用/ lib中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。 我錯過重要的事情嗎?任何建議傢伙?
你有沒有複選文件名? –
是的。我已經仔細檢查過它們。我甚至創建了一個新文件,用不同的名稱命名它們,並將其與EUserRepository一起放入同一個文件夾中,並將其綁定到服務提供者中。和拉拉維爾仍然拋出同樣的錯誤。 – under5hell
嗨菲利普!爲什麼不將該文件夾註冊爲PSR-0或PSR-4? – hannesvdvreken