{"record":{"id":"70bf8bd65bb869d7","repo":"laravel/framework","slug":"target-concrete-is-not-instantiable-while-build","errorCode":null,"errorMessage":"Target [$concrete] is not instantiable while building [$previous].","messagePattern":"Target \\[\\$concrete\\] is not instantiable while building \\[\\$previous\\]\\.","errorType":"exception","errorClass":"BindingResolutionException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Container/Container.php","lineNumber":1436,"sourceCode":"    /**\n     * Throw an exception that the concrete is not instantiable.\n     *\n     * @param  string  $concrete\n     * @return void\n     *\n     * @throws \\Illuminate\\Contracts\\Container\\BindingResolutionException\n     */\n    protected function notInstantiable($concrete)\n    {\n        if (! empty($this->buildStack)) {\n            $previous = implode(', ', $this->buildStack);\n\n            $message = \"Target [$concrete] is not instantiable while building [$previous].\";\n        } else {\n            $message = \"Target [$concrete] is not instantiable.\";\n        }\n\n        throw new BindingResolutionException($message);\n    }\n\n    /**\n     * Throw an exception for an unresolvable primitive.\n     *\n     * @return void\n     *\n     * @throws \\Illuminate\\Contracts\\Container\\BindingResolutionException\n     */\n    protected function unresolvablePrimitive(ReflectionParameter $parameter)\n    {\n        $message = \"Unresolvable dependency resolving [$parameter] in class {$parameter->getDeclaringClass()->getName()}\";\n\n        throw new BindingResolutionException($message);\n    }\n\n    /**\n     * Register a new before resolving callback for all types.","sourceCodeStart":1418,"sourceCodeEnd":1454,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Container/Container.php#L1418-L1454","documentation":"BindingResolutionException from notInstantiable() when the container tries to build a non-instantiable type (interface, abstract class) as a transitive dependency of another class being built - i.e. buildStack is non-empty. The message lists the chain of classes already being constructed so you can see which dependency triggered it.","triggerScenarios":"Resolving a class whose constructor type-hints an interface that has no concrete binding; binding a concrete to an abstract but resolving a different consumer that depends on the abstract directly; forgetting to bind an interface in the provider for a nested dependency.","commonSituations":"Adding a new repository-interface dependency to a service but not binding the interface; environment where the service provider is not loaded; refactoring a class to depend on a contract that has no implementation registered.","solutions":["Bind the interface to a concrete implementation in a service provider: $this->app->bind(Contract::class, Implementation::class).","Read the buildStack in the message to identify exactly which dependency is the abstract, then bind that one.","If the abstract should resolve to itself, ensure it is a concrete instantiable class rather than an interface.","Confirm the relevant service provider appears in config/app.php (or is auto-discovered for packages)."],"exampleFix":"// before\nclass InvoiceService\n{\n    public function __construct(private InvoiceRepo $repo) {} // InvoiceRepo is an interface\n}\n// after - in AppServiceProvider::register()\n$this->app->bind(InvoiceRepo::class, DatabaseInvoiceRepo::class);","handlingStrategy":"validation","validationCode":"// Before resolving a class with interface-typed dependencies, ensure bindings exist.\n$r = new \\ReflectionClass(Service::class);\nforeach ($r->getConstructor()?->getParameters() ?? [] as $p) {\n    $type = $p->getType();\n    if ($type && ! $type->isBuiltin() && interface_exists($type->getName()) && ! app()->bound($type->getName())) {\n        throw new RuntimeException(\"Interface [\" . $type->getName() . \"] required by [Service] is not bound.\");\n    }\n}\napp()->make(Service::class);","typeGuard":"function dependenciesAreBound(string $class, \\Illuminate\\Container\\Container $c): bool\n{\n    $r = new \\ReflectionClass($class);\n    foreach ($r->getConstructor()?->getParameters() ?? [] as $p) {\n        $t = $p->getType();\n        if ($t && ! $t->isBuiltin() && (interface_exists($t->getName()) || (new \\ReflectionClass($t->getName()))->isAbstract())\n            && ! $c->bound($t->getName())) {\n            return false;\n        }\n    }\n    return true;\n}","tryCatchPattern":"use Illuminate\\Contracts\\Container\\BindingResolutionException;\n\ntry {\n    $service = app()->make(Service::class);\n} catch (BindingResolutionException $e) {\n    if (str_contains($e->getMessage(), 'not instantiable while building')) {\n        // read the build stack, bind the missing interface, retry\n    }\n    throw $e;\n}","preventionTips":["Always bind interface dependencies in service providers loaded in every environment.","Use ::class constants and PHPStan to catch unbound interfaces at static-analysis time.","Add a resolution smoke test per service in your test suite."],"tags":["container","di","binding","interface"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}