{"record":{"id":"d2548de1c2f8c9aa","repo":"laravel/framework","slug":"unable-to-resolve-dependency-parameter-in-cla","errorCode":null,"errorMessage":"Unable to resolve dependency [{$parameter}] in class {$parameter->getDeclaringClass()->getName()}","messagePattern":"Unable to resolve dependency \\[(.+?)\\] in class (.+?)","errorType":"exception","errorClass":"BindingResolutionException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Container/BoundMethod.php","lineNumber":200,"sourceCode":"\n                unset($parameters[$className]);\n            } elseif ($parameter->isVariadic()) {\n                $variadicDependencies = $container->make($className);\n\n                $pendingDependencies = array_merge($pendingDependencies, is_array($variadicDependencies)\n                    ? $variadicDependencies\n                    : [$variadicDependencies]);\n            } elseif ($parameter->isDefaultValueAvailable() && ! $container->bound($className)) {\n                $pendingDependencies[] = $parameter->getDefaultValue();\n            } else {\n                $pendingDependencies[] = $container->make($className);\n            }\n        } elseif ($parameter->isDefaultValueAvailable()) {\n            $pendingDependencies[] = $parameter->getDefaultValue();\n        } elseif (! $parameter->isOptional() && ! array_key_exists($paramName, $parameters)) {\n            $message = \"Unable to resolve dependency [{$parameter}] in class {$parameter->getDeclaringClass()->getName()}\";\n\n            throw new BindingResolutionException($message);\n        }\n\n        foreach ($pendingDependencies as $dependency) {\n            $container->fireAfterResolvingAttributeCallbacks($parameter->getAttributes(), $dependency);\n        }\n\n        $dependencies = array_merge($dependencies, $pendingDependencies);\n    }\n\n    /**\n     * Determine if the given string is in Class@method syntax.\n     *\n     * @param  mixed  $callback\n     * @return bool\n     */\n    protected static function isCallableWithAtSign($callback)\n    {\n        return is_string($callback) && str_contains($callback, '@');","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Container/BoundMethod.php#L182-L218","documentation":"Thrown during method/constructor dependency injection when a parameter is required (not optional, no default value), is not present in the caller-supplied parameter overrides, and the container cannot resolve it. Unlike the unresolvable-primitive case, this fires from BoundMethod::addDependencyForCallParameter for method calls where a typed dependency itself cannot be built or a non-optional parameter was not supplied.","triggerScenarios":"Invoking Container::call([$obj, 'doStuff']) where doStuff has a required $logger parameter that is not a resolvable class and is not passed; a controller method with a required non-class parameter (e.g. int $id) invoked by the router without route binding; a dependency whose concrete class is itself unresolvable while injecting into a method.","commonSituations":"Adding a new required constructor/method argument and forgetting to bind it; type-hinting an interface without a service provider binding; method signature changed but caller not updated; passing positional parameters in the wrong key so $parameters lookup by name fails.","solutions":["Give the parameter a default value, or make it nullable/optional if it is truly optional.","Bind the missing interface/abstract in a service provider: $this->app->bind(SomeContract::class, SomeImplementation::class).","Pass the parameter explicitly in the parameters array keyed by name: Container::call([$obj, 'doStuff'], ['id' => 42]).","Make the parameter a resolvable concrete class that the container can autowire."],"exampleFix":"// before\npublic function generate(ReportFormatter $formatter, $mode) { ... }\nContainer::call([$report, 'generate']);\n// after\nContainer::call([$report, 'generate'], ['mode' => 'csv']);\n// or bind the contract\n$this->app->bind(ReportFormatter::class, CsvFormatter::class);","handlingStrategy":"validation","validationCode":"// Before invoking a callable through the container, check its required params.\nfunction ensureResolvableMethodParams(\\ReflectionMethod $m, array $given): void\n{\n    foreach ($m->getParameters() as $p) {\n        $hasType = $p->getType() && ! $p->getType()->isBuiltin();\n        if (! $hasType && ! $p->isDefaultValueAvailable() && ! $p->isOptional() && ! array_key_exists($p->getName(), $given)) {\n            throw new \\InvalidArgumentException(\"Required parameter [{$p->getName()}] of [\" . $m->getDeclaringClass()->getName() . \"::{$m->getName()}] is not resolvable.\");\n        }\n    }\n}\n\n$r = new \\ReflectionMethod($obj, 'doStuff');\nensureResolvableMethodParams($r, $params);\nContainer::call([$obj, 'doStuff'], $params);","typeGuard":"function methodIsFullyResolvable(\\ReflectionMethod $m, array $given, \\Illuminate\\Container\\Container $c): bool\n{\n    foreach ($m->getParameters() as $p) {\n        $type = $p->getType();\n        $isClass = $type && ! $type->isBuiltin();\n        if ($p->isOptional() || $p->isDefaultValueAvailable() || array_key_exists($p->getName(), $given)) continue;\n        if (! $isClass || ! $c->bound($type->getName())) return false;\n    }\n    return true;\n}","tryCatchPattern":"use Illuminate\\Contracts\\Container\\BindingResolutionException;\n\ntry {\n    Container::call([$service, 'handle'], $params);\n} catch (BindingResolutionException $e) {\n    // log which dependency failed and either bind it or pass a parameter override\n    throw $e;\n}","preventionTips":["Prefer constructor injection over Container::call() with primitive params.","Keep required scalar params out of container-resolved constructors; inject config values explicitly.","Bind every interface a class transitively depends on, in service providers loaded in all environments."],"tags":["container","di","dependency-injection"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}