{"id":"996592479d7445ab","repo":"laravel/framework","slug":"the-s-method-may-not-be-called-on-model-s-wh","errorCode":null,"errorMessage":"The [%s] method may not be called on model [%s] while it is being booted.","messagePattern":"The \\[(.+?)\\] method may not be called on model \\[(.+?)\\] while it is being booted\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"critical","filePath":"src/Illuminate/Database/Eloquent/Model.php","lineNumber":336,"sourceCode":"        $this->bootIfNotBooted();\n        $this->initializeTraits();\n        $this->initializeModelAttributes();\n        $this->syncOriginal();\n        $this->fill($attributes);\n    }\n\n    /**\n     * Check if the model needs to be booted and if so, do it.\n     *\n     * @return void\n     *\n     * @throws \\LogicException\n     */\n    protected function bootIfNotBooted()\n    {\n        if (! isset(static::$booted[static::class])) {\n            if (isset(static::$booting[static::class])) {\n                throw new LogicException('The ['.__METHOD__.'] method may not be called on model ['.static::class.'] while it is being booted.');\n            }\n\n            static::$booting[static::class] = true;\n\n            $this->fireModelEvent('booting', false);\n\n            static::booting();\n            static::boot();\n\n            static::$booted[static::class] = true;\n            unset(static::$booting[static::class]);\n\n            static::booted();\n\n            static::$bootedCallbacks[static::class] ??= [];\n\n            foreach (static::$bootedCallbacks[static::class] as $callback) {\n                $callback();","sourceCodeStart":318,"sourceCodeEnd":354,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Eloquent/Model.php#L318-L354","documentation":"Thrown by bootIfNotBooted() when a model is already in the middle of booting (the static $booting flag is set for that class). Booting is meant to run once per class; if something triggered during boot (e.g. a booted callback, a booting() override, or a global scope registration) itself instantiates or queries the same model, it re-enters boot and hits the guard. The message includes the offending __METHOD__ and class name.","triggerScenarios":"Performing an action inside booting()/boot()/booted() (or a booted callback registered via Model::booted) that constructs or resolves the same model class, e.g. querying User::all() inside User::booted() before boot completes.","commonSituations":"Registering global scopes or observers that themselves instantiate the model, seeding during boot, or calling static model methods from within a boot override. Also occurs when two traits collaborate to recursively boot.","solutions":["Defer any work that instantiates/queries the model until after boot completes (use the 'booted' event or a callback registered via Model::booted(fn) which runs after the booted flag is set).","Move query/seed logic out of boot()/booting() into a dedicated artisan command or service provider that runs after the framework bootstraps.","Audit booted callbacks and global scopes registered during boot for any static model instantiation of the same class."],"exampleFix":"// before\nprotected static function boot()\n{\n    parent::boot();\n    self::all()->each(fn ($u) => $u->touch()); // re-enters boot\n}\n\n// after\nprotected static function boot()\n{\n    parent::boot();\n    static::created(fn ($u) => $u->touch());\n}","handlingStrategy":"validation","validationCode":"// Avoid instantiating/querying the same model during boot.\n// Move such logic to a booted callback that runs after the booted flag is set:\n\\Illuminate\\Database\\Eloquent\\Model::created(function ($model) {\n    // safe: boot is complete\n});","typeGuard":null,"tryCatchPattern":"try {\n    User::all();\n} catch (\\LogicException $e) {\n    if (str_contains($e->getMessage(), 'while it is being booted')) {\n        // defer work to after boot\n    }\n    throw $e;\n}","preventionTips":["Never query or instantiate the same model inside boot/booting/booted overrides.","Use static lifecycle events (created/updated) or Model::booted(fn) for post-boot work.","Audit global scopes and observers for re-entrant model access during boot."],"tags":["eloquent","boot-lifecycle","recursion","concurrency"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}