Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 841
RomeNYRR Avatar asked Oct 15 '25 15:10

RomeNYRR


1 Answers

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

like image 186
Raheel Avatar answered Oct 18 '25 05:10

Raheel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!