{"record":{"id":"3e4a45f126b5762c","repo":"laravel/framework","slug":"the-method-method-may-not-be-called-on-mod","errorCode":null,"errorMessage":"The [{__METHOD__}] method may not be called on model [{static::class}] 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":337,"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":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Eloquent/Model.php#L319-L355","documentation":"Thrown by Model::bootIfNotBooted() when a model is instantiated while that same model class is still mid-boot. The framework sets a $booting flag during static::boot()/booting()/booted() callbacks; encountering that flag again means a callback created a new instance of the current model, creating a re-entrant boot cycle that would otherwise recurse infinitely.","triggerScenarios":"Inside boot(), booting(), or booted() (or a registered boot listener) on Model X, code does 'new X()' or X::query()->first()/X::create([...]) which triggers bootIfNotBooted() on X again while X::$booting[X] is still true.","commonSituations":"A boot listener that seeds data by inserting the same model; a global scope registered during boot that queries the model immediately; observers attached in boot that instantiate the model; trait boot methods that warm caches by loading rows of the same model.","solutions":["Move any code that instantiates or queries the same model OUT of boot/booting/booted and into a deferred location (a service provider's boot() that uses the model, an Artisan command, or a lazy callback).","If you must touch rows during boot, query a different model or use the base query builder (DB::table) to avoid re-entering the model's boot.","Break the cycle by deferring with dispatch() or resolving the model after first request."],"exampleFix":"// before - causes re-entrant boot\nclass User extends Model\n{\n    public static function boot()\n    {\n        parent::boot();\n        static::created(function ($user) { /* ok */ });\n        // WRONG: instantiates User during User's own boot\n        $seed = User::where('email', 'admin@example.com')->first();\n    }\n}\n\n// after - defer the query out of boot\nclass User extends Model { /* boot only registers listeners */ }\n// in a ServiceProvider::boot() or via App::booted()\nApp::booted(fn () => User::where('email', 'admin@example.com')->first());","handlingStrategy":"validation","validationCode":"// Never instantiate or query the SAME model inside boot/booting/booted.\n// Move such work out of boot entirely, e.g. into App::booted()\nApp::booted(function () {\n    User::where('email', 'seed@example.com')->firstOrCreate([...]);\n});","typeGuard":null,"tryCatchPattern":"try {\n    $model = new User; // triggers boot\n} catch (\\LogicException $e) {\n    if (str_contains($e->getMessage(), 'while it is being booted')) {\n    //    Log and defer the instantiation to a booted callback.\n        App::booted(fn () => new User);\n    } else { throw $e; }\n}","preventionTips":["Keep boot/booting/booted limited to registering listeners and scopes - never instantiate the same model.","Use DB::table() or a different model if you must touch rows during boot.","Defer seeding/warming to App::booted or a ServiceProvider that runs after boot.","Audit trait boot methods when adding them - they share the re-entrancy risk."],"tags":["eloquent","booting","lifecycle","re-entrancy","model"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}