{"record":{"id":"8bfd3e6c32d1c482","repo":"laravel/framework","slug":"contextual-binding-attribute-attribute-getname","errorCode":null,"errorMessage":"Contextual binding attribute [{$attribute->getName()}] has no registered handler.","messagePattern":"Contextual binding attribute \\[(.+?)\\] has no registered handler\\.","errorType":"exception","errorClass":"BindingResolutionException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Container/Container.php","lineNumber":1412,"sourceCode":"    /**\n     * Resolve a dependency based on an attribute.\n     *\n     * @return mixed\n     *\n     * @throws \\Illuminate\\Contracts\\Container\\BindingResolutionException\n     */\n    public function resolveFromAttribute(ReflectionAttribute $attribute, ReflectionParameter $parameter)\n    {\n        $handler = $this->contextualAttributes[$attribute->getName()] ?? null;\n\n        $instance = $attribute->newInstance();\n\n        if (is_null($handler) && method_exists($instance, 'resolve')) {\n            $handler = $instance->resolve(...);\n        }\n\n        if (is_null($handler)) {\n            throw new BindingResolutionException(\"Contextual binding attribute [{$attribute->getName()}] has no registered handler.\");\n        }\n\n        return $handler($instance, $this, $parameter);\n    }\n\n    /**\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","sourceCodeStart":1394,"sourceCodeEnd":1430,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Container/Container.php#L1394-L1430","documentation":"BindingResolutionException from resolveFromAttribute() when a PHP 8 attribute applied to an injectable parameter has neither a registered contextual-attribute handler in the container nor a resolve() method on the attribute instance itself. The container resolves such attributes either via a registered Closure or by calling $instance->resolve(); if neither exists it cannot produce a value.","triggerScenarios":"Using a custom #[MyAttribute] attribute on a constructor parameter but never registering it via Context::registerAttribute() / $container->contextualAttributes[]; using a built-in attribute whose handler registration was skipped; attribute class implemented without a resolve() method.","commonSituations":"Migrating to PHP 8 attribute-based injection without wiring the handler; package providing the attribute but its service provider not loaded; renaming the attribute class so the registered FQCN no longer matches.","solutions":["Register a handler: Illuminate\\Container\\Context::registerAttribute(MyAttribute::class, fn (...) => $value) or set $container->contextualAttributes[MyAttribute::class].","Add a public resolve() method to the attribute class returning the injected value.","Ensure the service provider that registers contextual attributes is actually loaded in config/app.php.","Verify the attribute FQCN used in code matches the registered key exactly (namespace/renaming)."],"exampleFix":"// before\n#[StorageDisk('tmp')]\npublic function __construct(private $disk) {}\n// no handler registered\n// after\n// in a service provider boot():\nContext::registerAttribute(StorageDisk::class, function (StorageDisk $attr, Container $c) {\n    return Storage::disk($attr->disk);\n});","handlingStrategy":"validation","validationCode":"// Ensure every attribute used in injection has a handler.\nuse Illuminate\\Container\\Context;\n\n$attrClass = MyAttribute::class;\nif (! isset(app()->contextualAttributes[$attrClass]) && ! method_exists($attrClass, 'resolve')) {\n    Context::registerAttribute($attrClass, function (\\ReflectionAttribute $a, $container, $parameter) {\n        return /* resolved value */;\n    });\n}","typeGuard":"function attributeHasHandler(string $attributeClass, \\Illuminate\\Container\\Container $c): bool\n{\n    return isset($c->contextualAttributes[$attributeClass])\n        || method_exists($attributeClass, 'resolve');\n}","tryCatchPattern":"use Illuminate\\Contracts\\Container\\BindingResolutionException;\n\ntry {\n    $instance = app()->make(UsesAttributes::class);\n} catch (BindingResolutionException $e) {\n    if (str_contains($e->getMessage(), 'Contextual binding attribute')) {\n        // register the attribute handler in a provider, then retry\n    }\n    throw $e;\n}","preventionTips":["Register all contextual attribute handlers in a single boot() step in your app provider.","Add a resolve() method to attribute classes as a self-contained fallback handler.","Write a boot-time smoke test that resolves every attribute-using service."],"tags":["container","attributes","php8","contextual-binding","di"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}