otifsolutions / currency-layer
This Laravel package provides easy integration with Currency Layer Api along with complete list for countries with flag information. It also comes with command to auto sync rates for each currency
Installs: 73
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/otifsolutions/currency-layer
Requires
- ext-curl: *
- ext-dom: *
- ext-json: *
- otifsolutions/curl-handler: ^1
- otifsolutions/laravel-settings: ^1
README
Laravel Currency Layer
This Laravel package provides easy integration with Currency Layer Api along with complete list for countries with flag information. It also comes with command to auto sync rates for each currency
Requirements
PHP >= 7.4
Laravel >= 8.0
How to use the Library
Install via Composer (Recommended)
Using Composer
composer require otifsolutions/currency-layer
Note :
This package works with database engine
myIsam. If you are usingmysql databasethen you have to change database engine tomyIsamfrom config/database.php ->'connection' => 'mysql'and make this change'engine' => 'myIsam'
Now, run the migrations
php artisan migrate
Then, run this command to populate all tables with countries, states, currencies etc data
php artisan fill:tables
Now follow the instructions below
Grab the access key by registering on CurrencyLayer, give the key to the app using artisan tinker or by writing this line anywhere in the code, where yourAccessKey (string) is the key you've got from the API
OTIFSolutions\Laravel\Settings\Models\Setting::set('crlKey', 'yourAccessKey');
Set the numberOfDays key (positive integer), where this is the data of how many days you want to keep:
OTIFSolutions\Laravel\Settings\Models\Setting::set('daysRates', numberOfDays);
Note:
To check what key you have set, try with
getmethod like
OTIFSolutions\Laravel\Settings\Models\Setting::get('daysRates');
and
OTIFSolutions\Laravel\Settings\Models\Setting::get('crlKey');
If you have set the crlKey somewhere in the code, remove that line
after first time execution. To reset or re-assign the key, you can use the same line.
But, it is recommended to use tinker to set the access key.
After setting all the things, you can now synchronize currency exchange rates data
Hit this command to fetch the exchange rates
php artisan rates:get
Hit this command to remove the exchange rates
php artisan rates:delete
Now publish countries flags from package to your project
php artisan publish:flags
Note :
Commands
rates:deleteandrates:getcan only be executed when you set the keyscrlKeyanddaysRates
Relationships defined between Models
Model Country has OneToOne relation and Currency, ManyToMany relation with Timezone and OneToMany relation with State.
State Model has OneToMany relation with City
Currency Model has OneToMany relation with CurrencyRate