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

v1.0.1 2022-05-28 07:51 UTC

This package is auto-updated.

Last update: 2024-05-08 05:43:33 UTC


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 using mysql database then you have to change database engine to myIsam from 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 get method 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:delete and rates:get can only be executed when you set the keys crlKey and daysRates

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