Skip to content

CurrencyExchangeController ​

File: src/Http/Controllers/CurrencyExchangeController.php
Namespace: Unusualify\Modularous\Http\Controllers
Extends: Illuminate\Routing\Controller

Manages currency exchange rates and performs currency conversions. Delegates all business logic to the injected CurrencyExchangeService.

Constructor ​

php
public function __construct(CurrencyExchangeService $service)

Methods ​

fetchRates(): JsonResponse ​

Fetches the latest exchange rates from the configured provider and persists them to the database. Typically called via a scheduled job or an admin-triggered action.

convert(Request $request): JsonResponse ​

Converts an amount from the base currency to a target currency.

Validation:

FieldRulesDescription
amountrequired, numericAmount to convert
currencyrequired, size:3ISO 4217 target currency code

Returns the converted amount and the applied exchange rate.

getRate(Request $request, string $currency): JsonResponse ​

Returns the current exchange rate for a specific currency.

Route parameter:

ParameterRulesDescription
$currencysize:3ISO 4217 currency code
  • CurrencyExchangeService — underlying service that communicates with rate providers