/** * Execute the console command. * * @param \Jumilla\Versionia\Laravel\Migrator $migrator * * @return mixed */ public function handle(Migrator $migrator) { if (!$this->confirmToProceed()) { return; } $seed = $this->argument('name') ?: $migrator->defaultSeed(); if (!$seed) { $this->error('Default seed is not defined.'); return; } $class = $migrator->seedClass($seed); if (!$class) { $this->error("Seed '{$seed}' is not defined."); return; } $this->infoSeedRun($seed, $class); $seeder = new $class(); $seeder->setCommand($this)->run(); }
/** * Show seed infomation. * * @param \Jumilla\Versionia\Laravel\Migrator $migrator */ protected function showSeeds(Migrator $migrator) { $this->line('<comment>Seeds</comment>'); $seeds = $migrator->seedNames(); if (count($seeds) > 0) { $default_seed = $migrator->defaultSeed(); foreach ($seeds as $seed) { $class = $migrator->seedClass($seed); $status_mark = ' '; $default_mark = $seed == $default_seed ? '(default)' : ''; if (!class_exists($class)) { $this->line("{$status_mark} <info>[{$seed}]</info> <error>{$class}</error>"); $this->line(''); $this->error('Error: Class not found.'); continue; } $this->line("{$status_mark} <comment>{$default_mark}</comment><info>[{$seed}]</info> {$class}"); } if ($default_seed && !in_array($default_seed, $seeds)) { $this->line(''); $this->error("Error: default seed '{$default_seed}' is not defined."); } } else { $this->info('Nothing.'); } $this->line(''); }