可以这么说,我对“高级 Laravel”很陌生,但是我确实知道大部分基础知识,并且我试图了解命名空间、接口(interface)和存储库的全部内容,因为我不久前遇到过它。
但是,我收到以下错误,我不知道我做错了什么:
类 app\models\Interfaces\CategoriesInterface 不存在
下面是我的代码:
路由.php
App::bind('App\Models\Interfaces\BaseInterface', 'App\Models\Repositories\BaseRepository');
分类 Controller .php
<?php
use app\models\Interfaces\CategoriesInterface;
class CategoriesController extends BaseController
{
protected $categories;
public function __construct(CategoriesInterface $categories)
{
$this->categories = $categories;
}
基础接口(interface).php
<?php
interface BaseInterface
{
public function all();
}
CategoriesInterface.php
<?php namespace App\Models\Interfaces;
interface CategoriesInterface extends BaseInterface { }
CategoriesRepository.php
<?php namespace app\models\Repositories;
use App\Models\Interfaces\CategoriesInterface;
use Categories;
class CategoriesRepository implements CategoriesInterface
{
public function all()
{
$categories = $this->categories->all();
return $categories;
}
}
EloquentCategoriesRepository.php
<?php namespace app\models\Repositories;
use App\Models\Interfaces\CategoriesInterface;
class EloquentCategoriesRepository implements CategoriesInterface {
public function all()
{
return Categories::all();
}
最佳答案
尝试正确地命名类/接口(interface)的间距。 EloquentCategoriesRepository.php
和 CategoriesRepository
有 app
而不是 App
在命名空间中。和 CategoriesController
也需要使用App\..
不是 app\..
.
关于php - Laravel 错误接口(interface)类不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30953684/