$value]); if ($value === 0) { return new TransactionCurrency; } /** @var CurrencyRepositoryInterface $repository */ $repository = app(CurrencyRepositoryInterface::class, [$this->user]); if (isset($this->mapping[$value])) { Log::debug('Found currency in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]); $currency = $repository->find(intval($this->mapping[$value])); if (!is_null($currency->id)) { Log::debug('Found currency by ID', ['id' => $currency->id]); return $currency; } } // not mapped? Still try to find it first: $currency = $repository->findByName($value); if (!is_null($currency->id)) { Log::debug('Found currency by name ', ['id' => $currency->id]); return $currency; } // create new currency $currency = $repository->store( [ 'name' => $value, 'code' => strtoupper(substr($value, 0, 3)), 'symbol' => strtoupper(substr($value, 0, 1)), ] ); return $currency; } }