laravel/framework · error · InvalidArgumentException

Method [run] missing from {class}

Error message

Method [run] missing from {class}

What it means

Seeder.__invoke() requires every seeder class to define a run() method — that is the contract entry point the framework calls. If method_exists($this, 'run') is false, InvalidArgumentException is thrown before any work begins. The exception names the offending class so you can locate it.

Source

Thrown at src/Illuminate/Database/Seeder.php:180

    public function setCommand(Command $command)
    {
        $this->command = $command;

        return $this;
    }

    /**
     * Run the database seeds.
     *
     * @param  array  $parameters
     * @return mixed
     *
     * @throws \InvalidArgumentException
     */
    public function __invoke(array $parameters = [])
    {
        if (! method_exists($this, 'run')) {
            throw new InvalidArgumentException('Method [run] missing from '.get_class($this));
        }

        $callback = fn () => isset($this->container)
            ? $this->container->call([$this, 'run'], $parameters)
            : $this->run(...$parameters);

        if (isset(class_uses_recursive(static::class)[WithoutModelEvents::class])) {
            $callback = $this->withoutModelEvents($callback);
        }

        return $callback();
    }
}

View on GitHub (pinned to bd6b5437e6)

Solutions

  1. Add a public function run(): void { ... } method to the seeder class named in the message.
  2. Check for typos: the method must be exactly 'run' (case-sensitive).
  3. Ensure you are calling the intended concrete seeder, not an abstract base class.
  4. Run composer dump-autoload to clear a stale class map pointing at a stub.

Example fix

// before
namespace Database\Seeders;
class UserSeeder extends Seeder
{
    public function seed(): void
    {
        User::factory(10)->create();
    }
}

// after
namespace Database\Seeders;
class UserSeeder extends Seeder
{
    public function run(): void
    {
        User::factory(10)->create();
    }
}
Defensive patterns

Strategy: validation

Validate before calling

$class = \Database\Seeders\UserSeeder::class;
if (! method_exists($class, 'run')) {
    throw new \LogicException("{$class} must implement run()");
}
$this->call($class);

Type guard

/** @param class-string $seeder */
function isValidSeeder(string $seeder): bool
{
    return method_exists($seeder, 'run');
}

Prevention

When it happens

Trigger: Calling $this->call(SomeSeeder::class) or invoking a seeder (via db:seed or DatabaseSeeder) where SomeSeeder has no run() method — e.g. a class extending Seeder that only defines a helper method, or a typo (run vs Run, or a class used as a base/abstract without being meant to seed).

Common situations: Forgot to add run() after generating a seeder; renamed run() to something else; an abstract base seeder class being invoked directly; a seeder class that only defines call() invocations inside the wrong method name; namespace/class autoload mismatch loading an empty stub.

Related errors


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