{"record":{"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/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Container/Container.php#L1432-L1468","documentation":"BindingResolutionException from unresolvablePrimitive() when the container, while building a class, encounters a constructor parameter that is a primitive (non-class: int, string, bool, etc.), has no default value, and was not provided as an override. The container cannot guess a value for primitive parameters.","triggerScenarios":"Constructing a class like new class (int $timeout, Logger $log) where $timeout has no default and is not passed; resolving such a class via make() without overrides; a value-object with required scalar constructor args resolved through the container.","commonSituations":"Adding a required scalar config value to a constructor and forgetting to bind it; resolving value objects/DTOs through the container instead of new; refactor turning a method param into a constructor param without a default.","solutions":["Pass the value explicitly: $container->make(MyClass::class, ['timeout' => 30]).","Add a default value to the primitive parameter in the class.","Bind the parameter contextually using Context::when(...) needs ['$timeout' => 30].","Construct such objects with new instead of the container if they are plain value objects."],"exampleFix":"// before\nclass HttpClient\n{\n    public function __construct(private int $timeout, private Logger $log) {}\n}\napp(HttpClient::class); // throws\n// after\napp(HttpClient::class, ['timeout' => 30]);\n// or\n$this->app->when(HttpClient::class)\n    ->needs('$timeout')\n    ->give(config('http.timeout'));","handlingStrategy":"validation","validationCode":"// Identify required primitive constructor params and supply them.\n$r = new \\ReflectionClass(HttpClient::class);\n$needed = [];\nforeach ($r->getConstructor()?->getParameters() ?? [] as $p) {\n    $t = $p->getType();\n    if ($t && $t->isBuiltin() && ! $p->isDefaultValueAvailable() && ! $p->isOptional()) {\n        $needed[$p->getName()] = config(\"http.{$p->getName()}\");\n    }\n}\napp()->make(HttpClient::class, $needed);","typeGuard":"function hasUnresolvablePrimitive(string $class): bool\n{\n    foreach ((new \\ReflectionClass($class))->getConstructor()?->getParameters() ?? [] as $p) {\n        $t = $p->getType();\n        if ($t && $t->isBuiltin() && ! $p->isDefaultValueAvailable() && ! $p->isOptional()) {\n            return true;\n        }\n    }\n    return false;\n}","tryCatchPattern":"use Illuminate\\Contracts\\Container\\BindingResolutionException;\n\ntry {\n    app()->make(HttpClient::class);\n} catch (BindingResolutionException $e) {\n    if (str_contains($e->getMessage(), 'Unresolvable dependency resolving')) {\n        // supply the primitive via make() overrides or contextual binding\n        app()->make(HttpClient::class, ['timeout' => 30]);\n    }\n    throw $e;\n}","preventionTips":["Avoid resolving value objects / DTOs through the container; use new.","Give scalar constructor params sensible defaults or mark them nullable where possible.","Bind primitives contextually with Context::when(...) needs ['$x'] -> give(...)."],"tags":["container","di","primitive","binding"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}