{"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/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Container/Container.php#L1394-L1430","documentation":"Thrown by Container::resolveFromAttribute when a constructor/method parameter is decorated with an attribute that implements ContextualAttribute but neither a handler was registered via whenHasAttribute() nor the attribute class itself defines a resolve() method. The container must know how to materialise the value for the attribute, otherwise resolution fails.","triggerScenarios":"Using a custom #[MyContextualAttribute] attribute that implements ContextualAttribute but has no resolve() method, and the developer forgot to call $container->whenHasAttribute(MyContextualAttribute::class, fn (...) => $value).","commonSituations":"Building a custom contextual-attribute system and forgetting the handler registration; renaming resolve() to something else; attribute class extends a base that lost its resolve method in an upgrade.","solutions":["Register a handler: $this->app->whenHasAttribute(MyAttribute::class, fn (MyAttribute $attr, Container $c, $param) => $value).","Add a public resolve() method to your attribute class: public function resolve(self $attr, Container $container, ReflectionParameter $parameter): mixed { ... }.","Remove the attribute from the parameter if you do not actually need contextual resolution."],"exampleFix":"// before\n#[Attribute] class CurrentUser implements ContextualAttribute {}\n// used as: function handle(#[CurrentUser] User $user) {}\n\n// after\nclass CurrentUser implements ContextualAttribute\n{\n    public function resolve(self $attr, Container $container, $parameter): User\n    {\n        return $container->make(Auth::class)->user();\n    }\n}","handlingStrategy":"try-catch","validationCode":"$attrClass = $attribute->getName();\nif (! isset($container->contextualAttributes[$attrClass])\n    && ! method_exists($attrClass, 'resolve')) {\n    throw new \\LogicException(\"No handler for attribute {$attrClass}\");\n}","typeGuard":"function attributeHasHandler(string $attrClass, \\Illuminate\\Container\\Container $c): bool\n{\n    return isset($c->contextualAttributes[$attrClass])\n        || method_exists($attrClass, 'resolve');\n}","tryCatchPattern":"use Illuminate\\Contracts\\Container\\BindingResolutionException;\ntry {\n    app()->make($class);\n} catch (BindingResolutionException $e) {\n    if (str_contains($e->getMessage(), 'has no registered handler')) {\n        app()->whenHasAttribute(MyAttr::class, fn () => $default);\n    }\n    throw $e;\n}","preventionTips":["Register all custom attribute handlers in a dedicated service provider.","Implement resolve() on the attribute class itself as a default.","Static-analyse attribute usage against a known handler registry."],"tags":["container","attributes","contextual-binding","di"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}