{"id":"aaa3556d3589fa68","repo":"laravel/framework","slug":"unresolvable-dependency-resolving-parameter-in","errorCode":null,"errorMessage":"Unresolvable dependency resolving [$parameter] in class {$parameter->getDeclaringClass()->getName()}","messagePattern":"Unresolvable dependency resolving \\[\\$parameter\\] in class (.+?)","errorType":"exception","errorClass":"BindingResolutionException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Container/Container.php","lineNumber":1450,"sourceCode":"        } 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.\n     *\n     * @param  \\Closure|string  $abstract\n     * @return void\n     */\n    public function beforeResolving($abstract, ?Closure $callback = null)\n    {\n        if (is_string($abstract)) {\n            $abstract = $this->getAlias($abstract);\n        }\n\n        if ($abstract instanceof Closure && is_null($callback)) {\n            $this->globalBeforeResolvingCallbacks[] = $abstract;\n        } else {\n            $this->beforeResolvingCallbacks[$abstract][] = $callback;","sourceCodeStart":1432,"sourceCodeEnd":1468,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Container/Container.php#L1432-L1468","documentation":"Thrown by Container::unresolvablePrimitive during dependency resolution when a constructor parameter is a primitive (non-class) type with no default value, no contextual binding for '$name', is not nullable, and is not variadic. The container cannot fabricate an int/string/bool so it errors, naming the parameter and declaring class.","triggerScenarios":"A class __construct(public int $timeout) resolved via app()->make() without supplying ['timeout' => 30]; any primitive scalar required by a constructor that the container is asked to auto-resolve.","commonSituations":"Adding a new required scalar config parameter to a service constructor; switching a value object to container-resolved without passing parameters; missing config values that used to be injected via service provider.","solutions":["Pass the parameter when resolving: app()->make(Service::class, ['timeout' => 30]).","Register a contextual binding for the primitive: $this->app->when(Service::class)->needs('$timeout')->give(30).","Give the parameter a default value (int $timeout = 60), make it nullable (?int $timeout = null), or make it variadic.","Bind the whole class with a Closure that supplies the primitive."],"exampleFix":"// before\nclass HttpClient { public function __construct(public int $timeout) {} }\napp()->make(HttpClient::class);\n\n// after\napp()->bind(HttpClient::class, fn () => new HttpClient(config('http.timeout', 30)));","handlingStrategy":"validation","validationCode":"$r = new \\ReflectionMethod($class, '__construct');\nforeach ($r->getParameters() as $p) {\n    if ($p->hasType() && $p->getType()->isBuiltin() && ! $p->isDefaultValueAvailable()\n        && ! $p->isVariadic() && ! $p->allowsNull()\n        && ! array_key_exists($p->getName(), $params)) {\n        throw new \\InvalidArgumentException(\"Primitive \\${$p->getName()} required\");\n    }\n}","typeGuard":"function primitivesHaveDefaultsOrFail(string $class): bool\n{\n    foreach ((new \\ReflectionMethod($class, '__construct'))->getParameters() as $p) {\n        if ($p->getType()?->isBuiltin() && ! $p->isDefaultValueAvailable() && ! $p->allowsNull()) return false;\n    }\n    return true;\n}","tryCatchPattern":"use Illuminate\\Contracts\\Container\\BindingResolutionException;\ntry {\n    app()->make(Service::class);\n} catch (BindingResolutionException $e) {\n    if (str_contains($e->getMessage(), 'Unresolvable dependency')) {\n        app()->bind(Service::class, fn () => new Service(default: 30));\n    }\n    throw $e;\n}","preventionTips":["Always give primitive constructor params a default.","Use contextual primitive bindings ($this->app->when(...)->needs('$x')->give(...)).","Resolve services via a Closure that supplies config."],"tags":["container","primitive","dependency-injection","di","configuration"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}