K
K
Konstantin2018-12-12 23:56:39
Laravel
Konstantin, 2018-12-12 23:56:39

Class initialization error in provider?

View error:

Target [App\Services\OrderServiceInterface] is not instantiable.

public function register()
    {
        $this->app->bind('App\Services\OrderServiceInterface', OrderService::class);
    }

Where is the OrderServiceInterface interface:
<?php

namespace App\Services; 

interface OrderServiceInterface
{
    public function doSomethingUseful();   
}

And OrderService is a concrete class:
<?php

namespace App\Services;

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

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaliy Orlov, 2018-12-14
@Junart1

This error means that Laravel cannot find the binding.
First of all check that you are calling it via an interface, i.e.

public function __construct(OrderServiceInterface $orderService)
    {

Next, check the namespaces and file paths.
Also make sure the OrderService::class contains what you expect, try the full path, i.e. instead of
like this
well, and if nothing helps at all, then reverse from here /vendor/illuminate/container/Container.php
...
        $reflector = new ReflectionClass($concrete);

        // If the type is not instantiable, the developer is attempting to resolve
        // an abstract type such as an Interface of Abstract Class and there is
        // no binding registered for the abstractions so we need to bail out.
        if (! $reflector->isInstantiable()) {
            return $this->notInstantiable($concrete);
        }
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question