RomeNYRR
RomeNYRR

Reputation: 887

Laravel 5 | Multiple Seeders in DatabaseSeeder.php

I've created a few custom seeders and now i'm trying to get them to seed from DatabaseSeeder.php but it will only do one at a time

Current DatabaseSeeder.php

    <?php  
use Database\seeds\CandySeeder;
use Database\seeds\ChocolateSeeder;
use Database\seeds\AlmondSeeder;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model; 

class DatabaseSeeder extends Seeder {

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Model::unguard();

        $this->call ('FirewallModelsSeeder');
    }    

}

Here's I tried to run

public function run()
    {
        Model::unguard();

        $this->call ('CandySeeder', 'ChocolateSeeder', 'AlmondSeeder');
    }

and

public function run()
    {
        Model::unguard();

        $this->call arrary ('CandySeeder', 'ChocolateSeeder', 'AlmondSeeder');
    }

Only CandySeeder runs =/ - I have to move the one i want to be ran to the first in line. Is there a way to pass a list so they can all run. I tried having 1 line for each, but db:seed gave me an error that it couldn't redeclare seeder

Upvotes: 4

Views: 4268

Answers (3)

Ger
Ger

Reputation: 258

In laravel 8:

$this->call([UsersSeeder::class,RolesSeeder:class]);

Upvotes: 0

Raheel
Raheel

Reputation: 9024

public function run()
    {
        Model::unguard();
        $seeders = array ('CandySeeder', 'ChocolateSeeder', 'AlmondSeeder');

        foreach ($seeders as $seeder)
        { 
           $this->call($seeder);
        }
    }

simply run the call function inside a loop

Upvotes: 5

Tedy Carrasco
Tedy Carrasco

Reputation: 41

In Laravel 5.1 :

Model::unguard();
$this->call(UsersAdminSeeder::class);
$this->call(TipoUsuarioTableSeeder::class);
Model::reguard();

Upvotes: 4

Related Questions