提供程序中的错误类初始化?

时间:2018-12-12 21:16:35

标签: laravel laravel-5

错误视图:

  

目标[App \ Services \ OrderServiceInterface]无法实例化。

提供者:

   class OrderServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bind('App\Services\OrderServiceInterface', 'App\Services\OrderService');
    }
}

OrderServiceInterface 是接口:

<?php

namespace App\Services; 

interface OrderServiceInterface
{

    public function doSomethingUseful();

}

OrderService 是一个特定的类:

<?php

namespace App\Services;

class OrderService implements OrderServiceInterface
{
    public function doSomethingUseful()
    {
        return 'Output from DemoOne';
    }
}

用法:

public function accept(Request $request, OrderServiceInterface $orderService) {}

1 个答案:

答案 0 :(得分:2)

如果您的服务提供商似乎尚未注册,请尝试运行:

composer dump-autoload

php artisan cache:clear

感谢@adam

php artisan config:clear