Php 错误u_construct()必须是接口的实例,未给定任何实例

Php 错误u_construct()必须是接口的实例,未给定任何实例,php,laravel,Php,Laravel,我正在为Laravel开发一个软件包,但我遇到了一个无法解决的错误: 传递给Cartalini\Drayman\Drayman::uu construct()的参数1必须是Cartalini\Drayman\Repositories\UserRepositoryInterface的实例,未给定,在第10行的/Applications/MAMP/htdocs/l4/app/controllers/HomeController.php中调用并定义 这是我的密码 namespace Cartalini

我正在为Laravel开发一个软件包,但我遇到了一个无法解决的错误:

传递给Cartalini\Drayman\Drayman::uu construct()的参数1必须是Cartalini\Drayman\Repositories\UserRepositoryInterface的实例,未给定,在第10行的/Applications/MAMP/htdocs/l4/app/controllers/HomeController.php中调用并定义

这是我的密码

namespace Cartalini\Drayman;

use Cartalini\Drayman\Repositories\UserRepositoryInterface;

class Drayman
{
    protected $user;

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

    public function deliverBeer()
    {
        return $this->user->all();
    }
}
用户存储库

namespace Cartalini\Drayman\Repositories;

class UserRepository implements UserRepositoryInterface
{
    public function all()
    {
        return User::all();
    }
}
UserRepositoryInterface

namespace Cartalini\Drayman\Repositories;

interface UserRepositoryInterface
{
    public function all();
}
服务提供商

public function register()
{
    $this->app->bind('Cartalini\Drayman\Repositories\UserRepositoryInterface', 'Cartalini\Drayman\Repositories\UserRepository');
}
最后我的控制器

use Cartalini\Drayman\Drayman as Drayman;

class HomeController extends BaseController 
{
    public function showWelcome()
    {
        $drayman = new Drayman;
        return $drayman->deliverBeer();
    }
}

有人能帮我调试一下吗?

在您的
showWelcome
功能中:

public function showWelcome()
{
    // need to pass a UserRepositoryInterface object here:
    $drayman = new Drayman;
    return $drayman->deliverBeer();
}

由于您没有传递代码所需的
UserRepositoryInterface
对象,因此出现了该错误。

您是否尝试读取错误消息?消息说明了一切
Daryamn
需要类型为
UserRepositoryInterface
的参数,但您没有提供。请关注和阅读Laravel中的包开发文章,我认为您遗漏了两件事。这不是
Laravel
的工作方式,这是关于,这在理论上是正确的,但在这种情况下不是正确的答案。你知道拉威尔是如何工作的吗?检查我在之前的评论中给出的链接。我知道什么并不重要,但事实上你不知道
Laravel
,你回答了什么,如何在这里传递依赖关系,你甚至没有给出任何示例,你能做对吗?你在这里有什么建议来解决问题,任何代码示例?根据普通的
PHP
,您甚至没有给出正确的代码,您在答案中的依赖项是在哪里传递的?^建议是关于答案
//需要在此处传递UserRepositoryInterface对象: