124697
124697

Reputation: 21893

Calling php artisan db:seed does not work without providing a class name

I have a seeder class in the database folder

class UsersTableSeeder extends Seeder
{
    public function run()
    {
        $user = new User();
        $user->name         = 'Name';
        $user->email        = '[email protected]';
        $user->password        = bcrypt('secret');
        $user->save();

    }
}

When I run php artisan db:seed nothing happens, the seeder is only called when I run php artisan db:seed --class=UsersTableSeeder

This means I have to call each seeder class separately, any idea why db:seed doesn't work by it self?

Upvotes: 2

Views: 1572

Answers (3)

Mike
Mike

Reputation: 187

Take a look at database/seeds/DatabaseSeeder.php

You will need to add the calls to your other seeders in there.

Then db:seed will function as expected

Example:

<?php

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $this->call(UsersTableSeeder::class);
        $this->call(SecondSeedClass::class);
        $this->call(ThirdSeedClass::class);

    }
}

Upvotes: 3

Rahman Qaiser
Rahman Qaiser

Reputation: 672

You have to register the seed classes in DatabaseSeeder class in seeds folder. All the classes in run method will be seed on php artisab db:seed command

class DatabaseSeeder extends Seeder {

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run() {
        $this->call(UsersTableSeeder::class);
        $this->call(AnotherSeeder::class);

    }

}

Upvotes: 2

Alexey Mezenin
Alexey Mezenin

Reputation: 163798

You need to add it to the DatabaseSeeder class:

public function run()
{
    $this->call(UsersTableSeeder::class);
}

Upvotes: 1

Related Questions