PHPackages                             xdemonme/laravel-currency - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. xdemonme/laravel-currency

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

xdemonme/laravel-currency
=========================

A Laravel package for current and historical currency exchange rates &amp; crypto exchange rates based on the free API provided by exchangerate.host

1.1.0(2y ago)31131[1 PRs](https://github.com/xDemonME/laravel-currency/pulls)MITPHPPHP &gt;=7.2

Since Oct 20Pushed 2y agoCompare

[ Source](https://github.com/xDemonME/laravel-currency)[ Packagist](https://packagist.org/packages/xdemonme/laravel-currency)[ Fund](https://ko-fi.com/amrshawky)[ RSS](/packages/xdemonme-laravel-currency/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

Laravel Currency
================

[](#laravel-currency)

[![Tests](https://github.com/amrshawky/laravel-currency/workflows/Tests/badge.svg?branch=master)](https://github.com/amrshawky/laravel-currency/workflows/Tests/badge.svg?branch=master) [![Packagist License](https://camo.githubusercontent.com/a768bfe12d34fe766c8987c311b6a4761badc3afa28a2a9972f54626198267ad/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616d72736861776b792f6c61726176656c2d63757272656e63793f636f6c6f723d73756363657373266c6162656c3d4c6963656e7365)](https://camo.githubusercontent.com/a768bfe12d34fe766c8987c311b6a4761badc3afa28a2a9972f54626198267ad/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616d72736861776b792f6c61726176656c2d63757272656e63793f636f6c6f723d73756363657373266c6162656c3d4c6963656e7365) [![Packagist Version](https://camo.githubusercontent.com/9d48f8d79202eeb0bb884dd72cd6289c3d19f2d9cca2e48f78d09b14908acdf3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616d72736861776b792f6c61726176656c2d63757272656e63793f6c6162656c3d5061636b6167697374)](https://camo.githubusercontent.com/9d48f8d79202eeb0bb884dd72cd6289c3d19f2d9cca2e48f78d09b14908acdf3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616d72736861776b792f6c61726176656c2d63757272656e63793f6c6162656c3d5061636b6167697374) [![Packagist Downloads](https://camo.githubusercontent.com/9ce0dd4d122fd474230ac794dfd815ff9599833498ffd6a6de14690e7454bc43/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616d72736861776b792f6c61726176656c2d63757272656e63793f636f6c6f723d73756363657373266c6162656c3d446f776e6c6f616473)](https://camo.githubusercontent.com/9ce0dd4d122fd474230ac794dfd815ff9599833498ffd6a6de14690e7454bc43/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616d72736861776b792f6c61726176656c2d63757272656e63793f636f6c6f723d73756363657373266c6162656c3d446f776e6c6f616473)

> **This package supports exchangerate.host API keys.**

Laravel currency is a simple package for current and historical currency exchange rates &amp; crypto exchange rates. based on the free API [exchangerate.host](https://exchangerate.host "exchangerate.host Homepage")!

> Note: This package is an integration for the [Currency](https://github.com/xdemonme/currency) library

Requirements
------------

[](#requirements)

- PHP &gt;= 7.2
- Laravel &gt;= 6.0
- guzzlehttp &gt;= 6.0

Installation
------------

[](#installation)

```
composer require xdemonme/laravel-currency

```

Usage
-----

[](#usage)

### 1. Currency Conversion

[](#1-currency-conversion)

To convert from one currency to another you may chain the methods:

```
use AmrShawky\LaravelCurrency\Facade\Currency;

$accessKey = 'YOUR_API_ACCESS_KEY';

Currency::convert()
        ->setAccessKey($accessKey)
        ->from('USD')
        ->to('EUR')
        ->get();
```

This will return the converted amount or `null` on failure.

The amount to be converted is default to `1`, you may specify the amount:

```
use AmrShawky\LaravelCurrency\Facade\Currency;

$accessKey = 'YOUR_API_ACCESS_KEY';

Currency::convert()
        ->setAccessKey($accessKey)
        ->from('USD')
        ->to('EUR')
        ->amount(50)
        ->get();
```

#### Available Methods

[](#available-methods)

- Convert currency using historical exchange rates `YYYY-MM-DD`:

```
use AmrShawky\LaravelCurrency\Facade\Currency;

$accessKey = 'YOUR_API_ACCESS_KEY';

Currency::convert()
        ->setAccessKey($accessKey)
        ->from('USD')
        ->to('EUR')
        ->date('2019-08-01')
        ->get();
```

- Round the converted amount to decimal places:

```
use AmrShawky\LaravelCurrency\Facade\Currency;

$accessKey = 'YOUR_API_ACCESS_KEY';

Currency::convert()
        ->setAccessKey($accessKey)
        ->from('USD')
        ->to('EUR')
        ->round(2)
        ->get();
```

- You may also switch data source between forex `default`, bank view or crypto currencies:

```
use AmrShawky\LaravelCurrency\Facade\Currency;

$accessKey = 'YOUR_API_ACCESS_KEY';

Currency::convert()
        ->setAccessKey($accessKey)
        ->from('BTC')
        ->to('ETH')
        ->source('crypto')
        ->get();
```

### 2. Live (latest) Rates

[](#2-live-latest-rates)

> Note: This method is DEPRECATED

To get latest rates you may chain the methods:

```
use AmrShawky\LaravelCurrency\Facade\Currency;

$accessKey = 'YOUR_API_ACCESS_KEY';

Currency::rates()
        ->setAccessKey($accessKey)
        ->live()
        ->get();

// ['USD' =>  1.215707, ...]

Currency::rates()
        ->setAccessKey($accessKey)
        ->live()
        ->source('crypto')
        ->get();

// ['ETH' => 3398.61, ...]
```

This will return an `array` of all available currencies or `null` on failure.

#### Available Methods

[](#available-methods-1)

- Just like currency conversion you may chain any of the available methods:

```
use AmrShawky\LaravelCurrency\Facade\Currency;

$accessKey = 'YOUR_API_ACCESS_KEY';

Currency::rates()
        ->setAccessKey($accessKey)
        ->live()
        ->symbols(['USD', 'EUR', 'EGP']) //An array of currency codes to limit output currencies
        ->base('GBP') //Changing base currency (default: EUR). Enter the three-letter currency code of your preferred base currency.
        ->amount(5.66) //Specify the amount to be converted
        ->round(2) //Round numbers to decimal places
        ->source('ecb') //Switch data source between forex `default`, bank view or crypto currencies.
        ->get();
```

### 3. Historical Rates

[](#3-historical-rates)

Historical rates are available for most currencies all the way back to the year of 1999.

```
use AmrShawky\LaravelCurrency\Facade\Currency;

$accessKey = 'YOUR_API_ACCESS_KEY';

Currency::rates()
        ->setAccessKey($accessKey)
        ->historical('2020-01-01') //`YYYY-MM-DD` Required date parameter to get the rates for
        ->get();

// ['USD' =>  1.1185, ...]

Currency::rates()
        ->setAccessKey($accessKey)
        ->historical('2021-03-30')
        ->source('crypto')
        ->get();

// ['BTC' =>  2.0E-5, ...]
```

Same as latest rates you may chain any of the available methods:

```
use AmrShawky\LaravelCurrency\Facade\Currency;

$accessKey = 'YOUR_API_ACCESS_KEY';

Currency::rates()
        ->setAccessKey($accessKey)
        ->historical('2020-01-01')
        ->symbols(['USD', 'EUR', 'CZK'])
        ->base('GBP')
        ->amount(5.66)
        ->round(2)
        ->source('ecb')
        ->get();
```

### 4. Timeframe (timeseries) Rates

[](#4-timeframe-timeseries-rates)

Timeframe (timeseries) are for daily historical rates between two dates of your choice, with a maximum time frame of 365 days. This will return an `array` or `null` on failure.

```
use AmrShawky\LaravelCurrency\Facade\Currency;

$accessKey = 'YOUR_API_ACCESS_KEY';

Currency::rates()
        ->setAccessKey($accessKey)
        ->timeFrame('2021-05-01', '2021-05-02') //`YYYY-MM-DD` Required dates range parameters
        ->symbols(['USD']) //[optional] An array of currency codes to limit output currencies
        ->base('GBP') //[optional] Changing base currency (default: EUR). Enter the three-letter currency code of your preferred base currency.
        ->amount(5.66) //[optional] Specify the amount to be converted (default: 1)
        ->round(2) //[optional] Round numbers to decimal places
        ->source('ecb') //[optional] Switch data source between forex `default`, bank view or crypto currencies.
        ->get();

/**
[
    '2021-05-01' => [
        "USD" => 1.201995
    ],
    '2021-05-02' => [
        "USD" => 1.2027
    ]
]
 */
```

### 5. Change (fluctuations)

[](#5-change-fluctuations)

Retrieve information about how currencies fluctuate on a day-to-day basis, with a maximum time frame of 365 days. This will return an `array` or `null` on failure.

```
use AmrShawky\LaravelCurrency\Facade\Currency;

$accessKey = 'YOUR_API_ACCESS_KEY';

Currency::rates()
        ->setAccessKey($accessKey)
        ->change('2021-03-29', '2021-04-15') //`YYYY-MM-DD` Required dates range parameters
        ->symbols(['USD']) //[optional] An array of currency codes to limit output currencies
        ->base('GBP') //[optional] Changing base currency (default: EUR). Enter the three-letter currency code of your preferred base currency.
        ->amount(5.66) //[optional] Specify the amount to be converted (default: 1)
        ->round(2) //[optional] Round numbers to decimal places
        ->source('ecb') //[optional] Switch data source between forex `default`, bank view or crypto currencies.
        ->get();

/**
 [
    'USD' => [
        "start_rate" => 1.376454,
        "end_rate"   => 1.37816,
        "change"     => -0.001706,
        "change_pct" => -0.001239
        ]
 ]
 */
```

### Throwing Exceptions

[](#throwing-exceptions)

The default behavior is to return `null` for errors that occur during the request *(connection timeout, DNS errors, client or server error status code, missing API success parameter, etc.)*.

If you would like to throw an exception instead, you may use the `throw` method, The `throw` method returns the currency instance, allowing you to chain other methods:

```
use AmrShawky\LaravelCurrency\Facade\Currency;

$accessKey = 'YOUR_API_ACCESS_KEY';

Currency::convert()
        ->setAccessKey($accessKey)
        ->from('USD')
        ->to('EUR')
        ->amount(20)
        ->throw()
        ->get();
```

If you would like to perform some additional logic before the exception is thrown, you may pass a closure to the throw method:

```
use AmrShawky\LaravelCurrency\Facade\Currency;

$accessKey = 'YOUR_API_ACCESS_KEY';

Currency::convert()
        ->setAccessKey($accessKey)
        ->from('USD')
        ->to('EUR')
        ->amount(20)
        ->throw(function ($response, $e) {
            //
        })
        ->get();
```

### Other Methods

[](#other-methods)

- You may use the `withoutVerifying` method to indicate that TLS certificates should not be verified when sending the request:

```
use AmrShawky\LaravelCurrency\Facade\Currency;

$accessKey = 'YOUR_API_ACCESS_KEY';

Currency::convert()
        ->setAccessKey($accessKey)
        ->from('USD')
        ->to('EUR')
        ->withoutVerifying()
        ->get();
```

- You may specify additional [Guzzle request options](https://docs.guzzlephp.org/en/stable/request-options.html "Guzzle request options") using the `withOptions` method. The `withOptions` method accepts an array of key / value pairs:

```
use AmrShawky\LaravelCurrency\Facade\Currency;

$accessKey = 'YOUR_API_ACCESS_KEY';

Currency::rates()
        ->setAccessKey($accessKey)
        ->historical('2021-04-30')
        ->withOptions([
            'debug'   => true,
            'timeout' => 3.0
        ])
        ->get();
```

- The `when` method will execute the given callback when the first argument given to the method evaluates to true:

```
use AmrShawky\LaravelCurrency\Facade\Currency;

$accessKey = 'YOUR_API_ACCESS_KEY';

Currency::rates()
        ->setAccessKey($accessKey)
        ->latest()
        ->when(true, function ($rates) {
            // will execute
            $rates->symbols(['USD', 'EUR', 'EGP'])
                  ->base('GBP');
        })
        ->when(false, function ($rates) {
            // won't execute
            $rates->symbols(['HKD']);
        })
        ->get();
```

### Testing

[](#testing)

Currency uses Laravel facades which makes it easy to [mock](https://laravel.com/docs/8.x/mocking#mocking-facades "Mocking Laravel Facades") so it's not actually executed during the test:

```
use AmrShawky\LaravelCurrency\Facade\Currency;

$accessKey = 'YOUR_API_ACCESS_KEY';

Currency::shouldReceive('convert')
        ->once()
        ->andReturn(1.50);

Currency::shouldReceive('rates')
         ->once()
         ->andReturn(['EUR' => 1,'USD' => 1.215707]);
```

More information regarding list of bank sources [here](https://api.exchangerate.host/sources "List of bank sources")

For a list of all supported symbols [here](https://api.exchangerate.host/symbols "List of supported symbols") and list of crypto currencies [here](https://api.exchangerate.host/cryptocurrencies)

License
-------

[](#license)

The MIT License (MIT). Please see [LICENSE](../master/LICENSE) for more information.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 88.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

936d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d1d21ed7ca26a337853c97e7b354637d1993105a7e3d9dccd125766c6b18ce9f?d=identicon)[xDemon](/maintainers/xDemon)

---

Top Contributors

[![amrshawky](https://avatars.githubusercontent.com/u/17335226?v=4)](https://github.com/amrshawky "amrshawky (31 commits)")[![parth391](https://avatars.githubusercontent.com/u/4966579?v=4)](https://github.com/parth391 "parth391 (2 commits)")[![xDemonME](https://avatars.githubusercontent.com/u/46478206?v=4)](https://github.com/xDemonME "xDemonME (2 commits)")

---

Tags

laravelcurrencyexchange ratescurrency-converter

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/xdemonme-laravel-currency/health.svg)

```
[![Health](https://phpackages.com/badges/xdemonme-laravel-currency/health.svg)](https://phpackages.com/packages/xdemonme-laravel-currency)
```

###  Alternatives

[akaunting/laravel-money

Currency formatting and conversion package for Laravel

7825.3M18](/packages/akaunting-laravel-money)[ujjwal/currency-converter

Currency Converter Class with features of caching and identifying currency from country Code

49225.4k](/packages/ujjwal-currency-converter)[firefly-iii/data-importer

Firefly III Data Import Tool.

7545.8k](/packages/firefly-iii-data-importer)[bensampo/laravel-embed

Painless responsive embeds for videos, slideshows and more.

142146.8k](/packages/bensampo-laravel-embed)[glhd/conveyor-belt

14797.0k](/packages/glhd-conveyor-belt)[adrianorosa/laravel-geolocation

Laravel Geo Location package to get details for a given IP Address

6593.3k1](/packages/adrianorosa-laravel-geolocation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
