My Blog Posts

Immutable Laravel Currency Converter

Immutable Laravel Currency Converter


 

You must bring your own database or pool of currency conversion data and apply a data layer for conversions. Here's an exemplary warehouse from the project:

The following is an example of a currency conversion supported by the data store:

use Gocanto\Converter\Examples\CurrenciesRepositoryExample;
use Gocanto\Converter\Converter;
use Gocanto\Converter\RoundedNumber;

$repository = new CurrenciesRepositoryExample;
$converter = new Converter($repository);

$conversion = $converter
    ->withAmount(RoundedNumber::make(10))
    ->withCurrency('SGD')
    ->convertTo('USD');

You can learn more about this package, get all the setup instructions, and find the source code on GitHub in gocanto/converter.



Share this article


Comments (0)

Comment