From the command line run:
$ composer require restuniverse/currencySimply install the package and let Laravel do its magic.
Once installed you need to register the service provider with the application. Open up config/app.php and find the providers key.
'providers' => [
\RestUniverse\Currency\CurrencyServiceProvider::class,
]This package also comes with a facade, which provides an easy way to call the the class. Open up config/app.php and find the aliases key.
'aliases' => [
'Currency' => \RestUniverse\Currency\Facades\Currency::class,
];Run this on the command line from the root of your project:
php artisan vendor:publish --provider="RestUniverse\Currency\CurrencyServiceProvider" --tag=configA configuration file will be published to config/currency.php.
If currencies are going to be stored in the database.
php artisan vendor:publish --provider="RestUniverse\Currency\CurrencyServiceProvider" --tag=migrationsRun this on the command line from the root of your project to generate the table for storing currencies:
$ php artisan migratenote: Add your API_KEY to the .env file with (REST_UNIVERSE_API_KEY).
The simplest way to use these methods is through the helper function currency() or by using the facade. For the examples below we will use the helper method.
currency($amount, $from = null, $to = null, $format = true)Arguments:
$amount - The float amount to convert
$from - The current currency code of the amount. If not set, the application default will be used (see config/currency.php file).
$to - The currency code to convert the amount to. If not set, the user-set currency is used.
$format - Should the returned value be formatted.
Usage:
echo currency(12.00); // Will format the amount using the user selected currency
echo currency(12.00, 'USD', 'EUR'); // Will format the amount from the default currency to EURUpdate exchange rates from restuniverse.com. An API key is needed to use Rest Universe. Add yours to the config file.
php artisan currency:hydrateIf you discover any security related issues, please email security@restuniverse.com instead of using the issue tracker.