php - Laravel 错误接口(interface)类不存在

标签 php laravel interface namespaces repository

可以这么说,我对“高级 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.phpCategoriesRepositoryapp而不是 App在命名空间中。和 CategoriesController也需要使用App\..不是 app\.. .

关于php - Laravel 错误接口(interface)类不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30953684/

相关文章:

php - 如何隐藏配置文件以防止直接访问?

javascript - 使用 PHP 设置焦点并选择错误的内容元素

Java :Interface Method's Overriding

go - 创建需要其他可重复逻辑作为先决条件的函数(干净的代码)

laravel - 不能在有状态组件根元素上使用 v-for 因为它呈现多个元素?

go - Go语言上的接口(interface)函数调用

php - 查询后在 WordPress 中重定向?

php - mysql更新查询返回查询为空

php - 如何在 Laravel 的邮件中添加接受/拒绝按钮

javascript - pdftron复制错误的文本