{"record":{"id":"93565af3aa099121","repo":"barryvdh/laravel-ide-helper","slug":"cannot-generate-eloquent-helper","errorCode":null,"errorMessage":"Cannot generate Eloquent helper","messagePattern":"Cannot generate Eloquent helper","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Generator.php","lineNumber":98,"sourceCode":"    {\n        $app = app();\n        return $this->view->make('ide-helper::helper')\n            ->with('namespaces_by_extends_ns', $this->getAliasesByExtendsNamespace())\n            ->with('namespaces_by_alias_ns', $this->getAliasesByAliasNamespace())\n            ->with('real_time_facades', $this->getRealTimeFacades())\n            ->with('helpers', $this->detectHelpers())\n            ->with('include_fluent', $this->config->get('ide-helper.include_fluent', true))\n            ->render();\n    }\n\n    public function generateEloquent()\n    {\n        $name = 'Eloquent';\n        $facade = Model::class;\n        $magicMethods = array_key_exists($name, $this->magic) ? $this->magic[$name] : [];\n        $alias = new Alias($this->config, $name, $facade, $magicMethods, $this->interfaces);\n        if (!$alias->isValid()) {\n            throw new \\RuntimeException('Cannot generate Eloquent helper');\n        }\n\n        //Add extra methods, from other classes (magic static calls)\n        if (array_key_exists($name, $this->extra)) {\n            $alias->addClass($this->extra[$name]);\n        }\n\n        $app = app();\n        return $this->view->make('ide-helper::helper')\n            ->with('namespaces_by_extends_ns', [])\n            ->with('namespaces_by_alias_ns', ['__root' => [$alias]])\n            ->with('real_time_facades', [])\n            ->with('helpers', '')\n            ->with('include_fluent', false)\n            ->with('factories', [])\n            ->render();\n    }\n","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/barryvdh/laravel-ide-helper/blob/3a886dca5c7ec4854b316b1ac3bcdf9c43c1760b/src/Generator.php#L80-L116","documentation":"ide-helper:eloquent builds an Alias for the root class Illuminate\\Database\\Eloquent\\Model and renders `eloquent()` helper methods into the generated file (src/Generator.php:91-115). Before rendering, Alias::detectRoot() must confirm the root class actually exists; if `$this->root` stays null (or resolves to a trait) the alias is marked invalid and Generator throws this RuntimeException (src/Generator.php:97-99). In practice it means the Eloquent Model class could not be loaded in the current environment, usually a broken or incomplete vendor tree rather than an ide-helper misconfiguration.","triggerScenarios":"Running `php artisan ide-helper:eloquent` (or generating `ide-helper` with eloquent enabled) in an environment where class_exists('Illuminate\\Database\\Eloquent\\Model') is false: illuminate/database not installed (custom micro-app using only container/support components), a truncated or partially updated vendor directory, a stale optimized autoloader after upgrading laravel/framework, or running the command from a bootstrap that never registers the composer autoloader.","commonSituations":"Micro-services or test harnesses built on illuminate/components without Eloquent; CI images where `composer install` used --no-dev or a filtered vendor list; a git merge or partial deploy that left vendor/ half-written; local copy of the repo used outside a full Laravel application.","solutions":["Run `composer install` from the directory containing composer.lock so vendor/ is complete, then retry `php artisan ide-helper:eloquent`.","If Eloquent is genuinely absent, install it: `composer require illuminate/database` (or use a full `laravel/framework` application), matching the version of your other illuminate components.","Run `composer dump-autoload -o` to rebuild the class map when the package is present but not loadable.","If you do not need Eloquent helpers, drop the dedicated eloquent invocation and rely on `ide-helper:generate` alone."],"exampleFix":"# before: micro-app without Eloquent\n$ composer remove illuminate/database\n$ php artisan ide-helper:eloquent\nRuntimeException: Cannot generate Eloquent helper\n\n# after\n$ composer require illuminate/database\n$ php artisan ide-helper:eloquent\nA new helper file was written to _ide_helper.php","handlingStrategy":"validation","validationCode":"// Gate the command on Eloquent actually being loadable\nif (!class_exists(\\Illuminate\\Database\\Eloquent\\Model::class)) {\n    fwrite(STDERR, \"illuminate/database not installed; skipping ide-helper:eloquent\\n\");\n    return 1;\n}","typeGuard":null,"tryCatchPattern":"try {\n    \\Artisan::call('ide-helper:eloquent');\n} catch (\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'Cannot generate Eloquent helper')) {\n        // vendor tree incomplete or Eloquent absent; run composer install and retry\n        report($e);\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Pin the full framework in apps that run generation commands; keep composer.lock committed and install from it.","In slim illuminate-based apps, declare illuminate/database explicitly if you need Eloquent helpers.","Treat any 'class exists in source but not loadable' symptom as a vendor/autoloader defect: rebuild before debugging ide-helper."],"tags":["php","laravel","ide-helper","eloquent","composer","vendor"],"backgroundTag":"missing-package-class","analyzedSha":"3a886dca5c7ec4854b316b1ac3bcdf9c43c1760b","analyzedAt":"2026-08-23T00:48:42.471Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}