laravel/framework · critical · LogicException

The [%s] method may not be called on model [%s] while it is

Error message

The [%s] method may not be called on model [%s] while it is being booted.

What it means

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.

Source

Thrown at src/Illuminate/Database/Eloquent/Model.php:336

        $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 bd6b5437e6)

Solutions

  1. 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).
  2. Move query/seed logic out of boot()/booting() into a dedicated artisan command or service provider that runs after the framework bootstraps.
  3. Audit booted callbacks and global scopes registered during boot for any static model instantiation of the same class.

Example fix

// before
protected static function boot()
{
    parent::boot();
    self::all()->each(fn ($u) => $u->touch()); // re-enters boot
}

// after
protected static function boot()
{
    parent::boot();
    static::created(fn ($u) => $u->touch());
}
Defensive patterns

Strategy: validation

Validate before calling

// Avoid instantiating/querying the same model during boot.
// Move such logic to a booted callback that runs after the booted flag is set:
\Illuminate\Database\Eloquent\Model::created(function ($model) {
    // safe: boot is complete
});

Try / catch

try {
    User::all();
} catch (\LogicException $e) {
    if (str_contains($e->getMessage(), 'while it is being booted')) {
        // defer work to after boot
    }
    throw $e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06). Data as JSON: /data/errors/996592479d7445ab.json. Report an issue: GitHub.