{"record":{"id":"b75ceef18527e0b8","repo":"laravel/framework","slug":"unable-to-find-observer-class","errorCode":null,"errorMessage":"Unable to find observer: {$class}","messagePattern":"Unable to find observer: (.+?)","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Eloquent/Concerns/HasEvents.php","lineNumber":123,"sourceCode":"    /**\n     * Resolve the observer's class name from an object or string.\n     *\n     * @param  object|string  $class\n     * @return class-string\n     *\n     * @throws \\InvalidArgumentException\n     */\n    private function resolveObserverClassName($class)\n    {\n        if (is_object($class)) {\n            return get_class($class);\n        }\n\n        if (class_exists($class)) {\n            return $class;\n        }\n\n        throw new InvalidArgumentException('Unable to find observer: '.$class);\n    }\n\n    /**\n     * Get the observable event names.\n     *\n     * @return string[]\n     */\n    public function getObservableEvents()\n    {\n        return array_merge(\n            [\n                'retrieved', 'creating', 'created', 'updating', 'updated',\n                'saving', 'saved', 'restoring', 'restored', 'replicating',\n                'trashed', 'deleting', 'deleted', 'forceDeleting', 'forceDeleted',\n            ],\n            $this->observables\n        );\n    }","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php#L105-L141","documentation":"Thrown by resolveObserverClassName() when the value passed to an observer registration (e.g. Model::observe($class)) is a string that does not correspond to an existing class. The method resolves objects to their class, accepts existing class strings, and rejects anything class_exists() cannot find.","triggerScenarios":"Calling User::observe('App\\Observers\\UserObserver') where App\\Observers\\UserObserver does not exist (not defined, wrong namespace, or not autoloaded). Also passing a misspelled or fully-qualified-but-wrong class string.","commonSituations":"Registering observers in a service provider with a class string that was renamed or never created; the observer file exists but the namespace/filename mismatch prevents autoloading; copy-pasting an observe() call from another model without adjusting the class; missing composer dump-autoload after adding the file.","solutions":["Create the observer class at the given FQCN with the correct namespace and filename.","Verify the namespace and class name match exactly; run composer dump-autoload.","Pass the observer class constant (UserObserver::class) instead of a string to avoid typos.","Confirm the observer is registered in AppServiceProvider (or a dedicated provider) only after the class exists."],"exampleFix":"// before\nUser::observe('App\\Observers\\UserObserver'); // class does not exist\n\n// after\n// 1) create app/Observers/UserObserver.php with namespace App\\Observers;\nUser::observe(App\\Observers\\UserObserver::class);","handlingStrategy":"validation","validationCode":"$observerClass = App\\Observers\\UserObserver::class;\nif (! class_exists($observerClass)) {\n    throw new \\LogicException(\"Observer {$observerClass} does not exist; run composer dump-autoload or create the class.\");\n}\nUser::observe($observerClass);","typeGuard":"function observerClassExists(string $class): bool\n{\n    return class_exists($class);\n}","tryCatchPattern":null,"preventionTips":["Pass the observer's ::class constant rather than a literal string to catch typos early.","Create the observer file before registering it in the service provider.","Run composer dump-autoload after adding observer files."],"tags":["eloquent","observer","events","autoloading","configuration"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}