Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lilessam/currencies
Currencies Conversions Package For Laravel
https://github.com/lilessam/currencies
currency-rates laravel today-rates
Last synced: about 1 month ago
JSON representation
Currencies Conversions Package For Laravel
- Host: GitHub
- URL: https://github.com/lilessam/currencies
- Owner: lilessam
- Created: 2017-09-14T15:03:42.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-12-09T16:59:40.000Z (about 7 years ago)
- Last Synced: 2024-04-19T22:45:17.717Z (9 months ago)
- Topics: currency-rates, laravel, today-rates
- Language: PHP
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
### Currencies Package For Laravel
This package provides two simple helpers to convert amounts from currency to another and to get today's rates for any currency.
##### Helpers in the package are using an external API which provides real time currency rates.### Installation
via composer
```bash
composer require lilessam/currencies
```
Then add `Lilessam\Currencies\CurrenciesServiceProvider` to your providers array in `config/app.php`.### Using the package
You can use the helper `convert_currency` which requires three parameters. First is the amount, the second is the amount current currency and the third is the currency you want to change the amount to.
```PHP
// This will convert 10 from USD to EUR with today's price
$amount = convert_currency(10, 'USD', 'EUR');
```
You can also use `get_rates` helper to get an object of today's currencies rates. Its first parameter is required which is the base currency. The second parameter is optional and its type is array which allows you to pass what currencies you wanna get rates for.
```PHP
// This will return an object of all USD currencies today's rates
$rates = get_rates('USD');
// This will return an object of Euro, Indian Rubles and Arab Emirates Dirham rates for USD.
$rates = get_rates('USD', ['EUR', 'INR', 'AUD']);
```### Cache settings
The package now uses Laravel cache system to cache the data from the external API to reduce the API calls as much as possible. So you can use the following command to publish the package configuration file and change how many minutes you wanna keep the cached data.
```bash
php artisan vendor:publish --provider=Lilessam\Currencies\CurrenciesServiceProvider
```
The package caches the data for 60 minutes by default.###### The package has been developed in almost 30 mins, So please post any issue if found or make a pull request. Thanks !