public function run() { Countrycode::truncate(); $CHUNK_SIZE = 1024; $streamProvider = new Stream\File(dirname(__FILE__) . "/countrycodes.xml", $CHUNK_SIZE); $config = array("uniqueNode" => "row"); $parser = new Parser\UniqueNode($config); $streamer = new XmlStringStreamer($parser, $streamProvider); while ($node = $streamer->getNode()) { $simpleXmlNode = simplexml_load_string($node); Countrycode::create(['countrycode' => $simpleXmlNode->field[0], 'country' => $simpleXmlNode->field[1]]); } $this->command->info('Countrycode table seeded!'); }
public function fixLandcodes($data) { // $lc = $this->landcodes; $fields = array('country_of_destination', 'country_of_origin'); foreach ($fields as $field) { if (isset($data->{$field}) && strlen($data->{$field}) == 2) { try { $cc = Countrycode::where('countrycode', $data->{$field})->firstOrFail(); // Todo: caching inbouwen if (!empty($cc->country)) { $data->{$field} = $cc->country; } } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $exception) { \Log::error($data->{$field} . ' niet in Countrycode tabel gevonden'); } } } return $data; }