laravel/framework · critical · LogicException
The [{__METHOD__}] method may not be called on model [{stati
Error message
The [{__METHOD__}] method may not be called on model [{static::class}] while it is being booted. What it means
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.
Source
Thrown at src/Illuminate/Database/Eloquent/Model.php:337
$this->bootIfNotBooted();
$this->initializeTraits();
$this->initializeModelAttributes();
$this->syncOriginal();
$this->fill($attributes);
}
/**
* Check if the model needs to be booted and if so, do it.
*
* @return void
*
* @throws \LogicException
*/
protected function bootIfNotBooted()
{
if (! isset(static::$booted[static::class])) {
if (isset(static::$booting[static::class])) {
throw new LogicException('The ['.__METHOD__.'] method may not be called on model ['.static::class.'] while it is being booted.');
}
static::$booting[static::class] = true;
$this->fireModelEvent('booting', false);
static::booting();
static::boot();
static::$booted[static::class] = true;
unset(static::$booting[static::class]);
static::booted();
static::$bootedCallbacks[static::class] ??= [];
foreach (static::$bootedCallbacks[static::class] as $callback) {
$callback();View on GitHub (pinned to e0f6eb3518)
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.
Example fix
// before - causes re-entrant boot
class User extends Model
{
public static function boot()
{
parent::boot();
static::created(function ($user) { /* ok */ });
// WRONG: instantiates User during User's own boot
$seed = User::where('email', 'admin@example.com')->first();
}
}
// after - defer the query out of boot
class User extends Model { /* boot only registers listeners */ }
// in a ServiceProvider::boot() or via App::booted()
App::booted(fn () => User::where('email', 'admin@example.com')->first()); Defensive patterns
Strategy: validation
Validate before calling
// Never instantiate or query the SAME model inside boot/booting/booted.
// Move such work out of boot entirely, e.g. into App::booted()
App::booted(function () {
User::where('email', 'seed@example.com')->firstOrCreate([...]);
}); Try / catch
try {
$model = new User; // triggers boot
} catch (\LogicException $e) {
if (str_contains($e->getMessage(), 'while it is being booted')) {
// Log and defer the instantiation to a booted callback.
App::booted(fn () => new User);
} else { throw $e; }
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- No primary key defined on model.
- Resource collection guesser expects the collection to contai
- Expected class %s to implement guessResourceName method. Mak
- Failed to find resource class for model [%s].
- No record found for the given query.
AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11).
Data as JSON: /api/errors/3e4a45f126b5762c.
Report an issue: GitHub.