/** * Execute the console command. * * @return mixed */ public function handle() { /** @var Keytype $keytype */ $keytype = Keytype::create(['name' => 'countries', 'description' => 'ISO 3166 Country Codes', 'created_by' => 'loader', 'updated_by' => 'loader']); $handle = fopen($this->filename, 'r'); // Get this in advance by calling wc -l $file $count = 246; $bar = $this->output->createProgressBar($count); while ($data = fgetcsv($handle)) { try { list($country_code, $country_name) = $data; } catch (\Exception $e) { continue; } // progress advance $bar->advance(); // Skip the first line if ($country_code == "country_code") { continue; } // Create the entry Keyvalue::create(['keytype_id' => $keytype->id, 'keyvalue' => $country_code, 'keyname' => $country_name, 'created_by' => 'loader', 'updated_by' => 'loader']); } fclose($handle); $bar->finish(); $this->output->writeln('Finished'); }
/** * Run the database seeds. * * @return void */ public function run() { // // Create all of the address types // /** @var Keytype $keytype */ $keytype = Keytype::create(['name' => 'address-types', 'description' => 'Address Types']); Keyvalue::create(['keytype_id' => $keytype->id, 'keyvalue' => 'billing', 'keyname' => 'Billing Address']); Keyvalue::create(['keytype_id' => $keytype->id, 'keyvalue' => 'shipping', 'keyname' => 'Shipping Address']); Keyvalue::create(['keytype_id' => $keytype->id, 'keyvalue' => 'contact', 'keyname' => 'Contact Address']); Keyvalue::create(['keytype_id' => $keytype->id, 'keyvalue' => 'office', 'keyname' => 'Office Address']); Keyvalue::create(['keytype_id' => $keytype->id, 'keyvalue' => 'home', 'keyname' => 'Home Address']); Keyvalue::create(['keytype_id' => $keytype->id, 'keyvalue' => 'head-office', 'keyname' => 'Head Office Address']); Keyvalue::create(['keytype_id' => $keytype->id, 'keyvalue' => 'branch-office', 'keyname' => 'Branch Office Address']); // // Create all of the address statuses // /** @var Keytype $keytype */ $keytype = Keytype::create(['name' => 'address-statuses', 'description' => 'Address Statuses']); Keyvalue::create(['keytype_id' => $keytype->id, 'keyvalue' => 'current', 'keyname' => 'Current Address']); Keyvalue::create(['keytype_id' => $keytype->id, 'keyvalue' => 'previous', 'keyname' => 'Previous Address']); Keyvalue::create(['keytype_id' => $keytype->id, 'keyvalue' => 'future', 'keyname' => 'Future Address']); // // Name ordering rules // See https://en.wikipedia.org/wiki/Alphabetical_order#Ordering_by_surname // /** @var Keytype $keytype */ $keytype = Keytype::create(['name' => 'name-order', 'description' => 'Name Ordering Rules']); Keyvalue::create(['keytype_id' => $keytype->id, 'keyvalue' => 'en', 'keyname' => 'English Convention: Smith, John']); Keyvalue::create(['keytype_id' => $keytype->id, 'keyvalue' => 'nl', 'keyname' => 'Dutch/German/South African style: Merwe van der, Joost']); Keyvalue::create(['keytype_id' => $keytype->id, 'keyvalue' => 'cn', 'keyname' => 'China/Vietnam/Korea style: Park Geun-hye']); }
/** * Execute the console command. * * @return mixed */ public function handle() { /** @var Keytype $keytype */ $keytype = Keytype::create(['name' => 'timezones', 'description' => 'Time Zones', 'created_by' => 'loader', 'updated_by' => 'loader']); // Get this in advance $count = 417; $bar = $this->output->createProgressBar($count); $timezone_list = timezone_identifiers_list(); foreach ($timezone_list as $timezone) { // Create the entry Keyvalue::create(['keytype_id' => $keytype->id, 'keyvalue' => $timezone, 'keyname' => $timezone, 'created_by' => 'loader', 'updated_by' => 'loader']); // progress advance $bar->advance(); } // Finished $bar->finish(); $this->output->writeln('Finished'); }
/** * Execute the console command. * * @return mixed */ public function handle() { // To get the data from the openexchangerates.org site, then uncomment // these lines and substitute in your own app_id. /* $request_url = 'https://openexchangerates.org/api/latest.json'; $params = [ 'app_id' => 'YOUR_APP_ID_HERE', ]; $client = new \GuzzleHttp\Client(); $client->setDefaultOption('verify', false); $request_response = $client->get($request_url, ['query' => $params]); $response_data = json_decode($request_response->getBody()->getContents(), true); if (empty($response_data) or ! empty($response_data['error'])) { throw new \Exception('Empty response from api.'); } */ // To pull the data from the one off JSON file, then just use these // lines. $json_data = file_get_contents($this->filename); $response_data = json_decode($json_data, true); /** @var Keytype $keytype */ $keytype = Keytype::create(['name' => 'usd_rates', 'description' => 'USD Exchange Rates', 'created_by' => 'loader', 'updated_by' => 'loader']); // Get this in advance $ratedata = $response_data['rates']; $count = count($ratedata); $bar = $this->output->createProgressBar($count); foreach ($ratedata as $code => $rate) { $keyval = Keyvalue::firstOrNew(['keytype_id' => $keytype->id, 'keyvalue' => $code]); $keyval->keyname = "USD to {$code} Exchange Rate"; $keyval->extended_data = ['exchange_rate' => $rate]; $keyval->save(); // progress advance $bar->advance(); } // Finished $bar->finish(); $this->output->writeln('Finished'); }