/** * Execute the console command. * * @return mixed */ public function fire() { // Parse the CSV file and insert rows $this->info('Loading CSV...'); $countriesFile = new File($this->argument('file')); $countriesFile = $countriesFile->openFile(); $countriesFile->setFlags(SplFileObject::READ_CSV); $this->info('Beginning Import...'); $i = 0; foreach ($countriesFile as $country) { $i++; if ($i % 10 == 0) { $this->comment('Imported ' . $i . '...'); } if (isset($country[1]) && $i > 1) { $insertCountry = new Country(); $insertCountry->code = $country[1]; $insertCountry->name = $country[2]; $insertCountry->continent = $country[3]; $insertCountry->save(); } } $this->info('Import Complete! ' . $i . ' Countries Imported.'); }