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; }