laravel/framework · error · BindingResolutionException
Unresolvable dependency resolving [$parameter] in class {$pa
Error message
Unresolvable dependency resolving [$parameter] in class {$parameter->getDeclaringClass()->getName()} What it means
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.
Source
Thrown at src/Illuminate/Container/Container.php:1450
} else {
$message = "Target [$concrete] is not instantiable.";
}
throw new BindingResolutionException($message);
}
/**
* Throw an exception for an unresolvable primitive.
*
* @return void
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
protected function unresolvablePrimitive(ReflectionParameter $parameter)
{
$message = "Unresolvable dependency resolving [$parameter] in class {$parameter->getDeclaringClass()->getName()}";
throw new BindingResolutionException($message);
}
/**
* Register a new before resolving callback for all types.
*
* @param \Closure|string $abstract
* @return void
*/
public function beforeResolving($abstract, ?Closure $callback = null)
{
if (is_string($abstract)) {
$abstract = $this->getAlias($abstract);
}
if ($abstract instanceof Closure && is_null($callback)) {
$this->globalBeforeResolvingCallbacks[] = $abstract;
} else {
$this->beforeResolvingCallbacks[$abstract][] = $callback;View on GitHub (pinned to bd6b5437e6)
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.
Example fix
// before
class HttpClient { public function __construct(public int $timeout) {} }
app()->make(HttpClient::class);
// after
app()->bind(HttpClient::class, fn () => new HttpClient(config('http.timeout', 30))); Defensive patterns
Strategy: validation
Validate before calling
$r = new \ReflectionMethod($class, '__construct');
foreach ($r->getParameters() as $p) {
if ($p->hasType() && $p->getType()->isBuiltin() && ! $p->isDefaultValueAvailable()
&& ! $p->isVariadic() && ! $p->allowsNull()
&& ! array_key_exists($p->getName(), $params)) {
throw new \InvalidArgumentException("Primitive \${$p->getName()} required");
}
} Type guard
function primitivesHaveDefaultsOrFail(string $class): bool
{
foreach ((new \ReflectionMethod($class, '__construct'))->getParameters() as $p) {
if ($p->getType()?->isBuiltin() && ! $p->isDefaultValueAvailable() && ! $p->allowsNull()) return false;
}
return true;
} Try / catch
use Illuminate\Contracts\Container\BindingResolutionException;
try {
app()->make(Service::class);
} catch (BindingResolutionException $e) {
if (str_contains($e->getMessage(), 'Unresolvable dependency')) {
app()->bind(Service::class, fn () => new Service(default: 30));
}
throw $e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unable to resolve dependency [{$parameter}] in class {$param
- [{$abstract}] is aliased to itself.
- Target [$concrete] is not instantiable while building [$prev
- Circular alias reference for [{$abstract}].
- The environment property must be set and cannot be empty.
AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06).
Data as JSON: /data/errors/aaa3556d3589fa68.json.
Report an issue: GitHub.