Reputation: 887
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
<?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');
}
}
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
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
Reputation: 41
In Laravel 5.1 :
Model::unguard();
$this->call(UsersAdminSeeder::class);
$this->call(TipoUsuarioTableSeeder::class);
Model::reguard();
Upvotes: 4