コード例 #1
0
ファイル: ImportCountries.php プロジェクト: aorly/vAMSYS
 /**
  * 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.');
 }
コード例 #2
0
ファイル: ImportRegions.php プロジェクト: aorly/vAMSYS
 /**
  * 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.');
 }