Example #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     // Parse the CSV file and insert rows
     $this->info('Loading CSV...');
     $airportsFile = new File($this->argument('file'));
     $airportsFile = $airportsFile->openFile();
     $airportsFile->setFlags(SplFileObject::READ_CSV);
     $this->info('Beginning Import...');
     $i = 0;
     foreach ($airportsFile as $airport) {
         $i++;
         if ($i % 10 == 0) {
             $this->comment('Imported ' . $i . '...');
         }
         if (isset($airport[1]) && $i > 1) {
             $insertAirport = new Airport();
             $insertAirport->icao = $airport[1];
             $insertAirport->iata = $airport[13];
             $insertAirport->name = $airport[3];
             $insertAirport->latitude = $airport[4];
             $insertAirport->longitude = $airport[5];
             $insertAirport->region_id = Region::where('code', '=', $airport[9])->first()->id;
             $insertAirport->save();
         }
     }
     $this->info('Import Complete! ' . $i . ' Airports Imported.');
 }
Example #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     // Parse the CSV file and insert rows
     $this->info('Loading CSV...');
     $regionsFile = new File($this->argument('file'));
     $regionsFile = $regionsFile->openFile();
     $regionsFile->setFlags(SplFileObject::READ_CSV);
     $this->info('Beginning Import...');
     $i = 0;
     foreach ($regionsFile as $region) {
         $i++;
         if ($i % 10 == 0) {
             $this->comment('Imported ' . $i . '...');
         }
         if (isset($region[1]) && $i > 1) {
             $insertRegion = new Region();
             $insertRegion->code = $region[1];
             $insertRegion->name = $region[3];
             $insertRegion->country_id = Country::where('code', '=', $region[5])->first()->id;
             $insertRegion->save();
         }
     }
     $this->info('Import Complete! ' . $i . ' Regions Imported.');
 }