This package provides a simple and convenient interface for working with the Open Exchange Rates service. Currently supports free endpoints.
Add this to your composer.json
file, in the require object:
"equentor/laravel-open-exchange-rates": "dev-master"
After that, run composer install
to install the package.
Add the service provider to app/config/app.php
, within the providers array:
'providers' => [
// ...
Equentor\LaravelOpenExchangeRates\LOERServiceProvider::class,
]
Lastly, publish the config file.
php artisan vendor:publish
In config/loer.php
return [
'app_id' => '*****************************', // your own api key
'default_base_currency' => 'USD'
];
In controller (or service) method:
use Equentor\LaravelOpenExchangeRates\Client;
class SomeController extends Controller
{
private $client;
public function __construct(Client $client)
{
$this->client = $client;
}
public function someAction()
{
$coefficient = $this->client->latest('USD,RUB,AWG');
$historical_coefficent $this->client->historical('2011-03-05', 'USD,RUB,AWG');
// e.t.c...
// Change in base currencies (not allowed for free account) and requests for the coefficients of all currencies relative to.
$coefficient = $this->client->currency('RUB')->latest();
}
}