PHPackages                             centralbank/exchangerates - 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. centralbank/exchangerates

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

centralbank/exchangerates
=========================

Enhanced Central Bank of Myanmar Exchange Rates Laravel Package with caching, error handling, and service-based architecture.

v1.0.0(3y ago)08MITPHPPHP ^7.4|^8.0

Since Jun 6Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/Hein-Thu-Ya/ExchangeRates)[ Packagist](https://packagist.org/packages/centralbank/exchangerates)[ RSS](/packages/centralbank-exchangerates/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Central Bank of Myanmar Exchange Rates API for Laravel
======================================================

[](#central-bank-of-myanmar-exchange-rates-api-for-laravel)

\#SaveMyanmar
-------------

[](#savemyanmar)

Enhanced Central Bank of Myanmar Exchange Rates Laravel Package with caching, error handling, and service-based architecture.

**Version - 2.0.0**

Contact me -

Buy me a coffee - KBZ Pay (Hein Thu Ya) - 09978966317

Features
--------

[](#features)

- ✅ **Service-Based Architecture** - Clean service class for easy integration
- ✅ **Caching Support** - Reduces API calls with configurable cache duration
- ✅ **Error Handling** - Robust error handling and validation
- ✅ **Dynamic Currency Support** - Automatically supports all CBM currencies
- ✅ **Cache Management** - Manual cache refresh capability
- ✅ **Environment Configuration** - Configurable via environment variables
- ✅ **Dependency Injection** - Proper Laravel service container integration

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

[](#requirements)

- PHP 7.4 or Higher
- Laravel 8.0 or Higher (supports Laravel 8.x, 9.x, 10.x, 11.x)

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

[](#installation)

```
composer require centralbank/exchangerates
```

### Auto-Discovery

[](#auto-discovery)

Laravel will automatically discover the service provider. No manual registration needed.

### Manual Registration (Optional)

[](#manual-registration-optional)

If auto-discovery is disabled, add the ServiceProvider in `config/app.php`:

```
'providers' => [
    Centralbank\Exchangerates\ExchangeRatesServiceProvider::class
]
```

### Publish Configuration

[](#publish-configuration)

```
php artisan vendor:publish --tag=exchangerates-config
```

This creates `config/exchangerates-api.php` for customization.

Configuration
-------------

[](#configuration)

The package can be configured via environment variables:

```
# API URLs (optional - defaults to CBM official endpoints)
CBM_RATES_API=https://forex.cbm.gov.mm/api/latest
CBM_CURRENCIES_API=https://forex.cbm.gov.mm/api/currencies

# Cache settings
CBM_CACHE_DURATION=3600  # Cache duration in seconds (default: 1 hour)
CBM_CACHE_KEY=cbm_exchange_rates  # Cache key prefix

# API timeout
CBM_API_TIMEOUT=30  # Request timeout in seconds
```

Usage Examples
--------------

[](#usage-examples)

### Using the Service Class

[](#using-the-service-class)

#### In Controllers

[](#in-controllers)

```
use Centralbank\Exchangerates\Services\ExchangeRateService;

class YourController extends Controller
{
    protected $exchangeRateService;

    public function __construct(ExchangeRateService $exchangeRateService)
    {
        $this->exchangeRateService = $exchangeRateService;
    }

    public function getRates()
    {
        // Get all rates
        $allRates = $this->exchangeRateService->getAllRates();

        // Get specific currency
        $usdRate = $this->exchangeRateService->getRate('USD');

        // Get multiple currencies
        $rates = $this->exchangeRateService->getRates(['USD', 'EUR', 'GBP']);

        // Refresh cache
        $freshRates = $this->exchangeRateService->refreshCache();

        return response()->json($allRates);
    }
}
```

#### In Artisan Commands

[](#in-artisan-commands)

```
use Centralbank\Exchangerates\Services\ExchangeRateService;

class UpdateExchangeRatesCommand extends Command
{
    protected $signature = 'exchange:update';

    public function handle(ExchangeRateService $exchangeRateService)
    {
        $rates = $exchangeRateService->refreshCache();

        if ($rates) {
            $this->info('Exchange rates updated successfully!');
        } else {
            $this->error('Failed to update exchange rates.');
        }
    }
}
```

#### Using Facades (Optional)

[](#using-facades-optional)

You can create your own facade or use dependency injection as shown above.

Service Methods
---------------

[](#service-methods)

### `getAllRates()`

[](#getallrates)

Returns all available exchange rates with caching.

### `getRate(string $currencyCode)`

[](#getratestring-currencycode)

Returns exchange rate for a specific currency (e.g., 'USD', 'EUR').

### `getRates(array $currencyCodes)`

[](#getratesarray-currencycodes)

Returns exchange rates for multiple currencies.

### `refreshCache()`

[](#refreshcache)

Clears cache and fetches fresh data from CBM API.

### `clearCache()`

[](#clearcache)

Clears the cached exchange rates.

Response Format
---------------

[](#response-format)

### All Rates Response

[](#all-rates-response)

```
{
    "info": "...",
    "description": "...",
    "timestamp": "...",
    "rates": [
        {
            "rate": 2100.00,
            "currencies": "US Dollar",
            "symbol": "USD"
        }
    ]
}
```

### Single Currency Response

[](#single-currency-response)

```
{
    "rate": 2100.00,
    "currencies": "US Dollar",
    "symbol": "USD"
}
```

Changelog
---------

[](#changelog)

### v2.0.0

[](#v200)

- Removed all API routes and endpoints
- Implemented comprehensive error handling
- Added support for specific currency queries
- Added multiple currency endpoint
- Added cache refresh functionality
- Dynamic currency support (no hardcoded currencies)
- Environment-based configuration
- Converted to service-only architecture
- Package now provides only the ExchangeRateService class
- Developers must create their own controllers/routes if needed
- Cleaner, more flexible integration approach
- Added proper dependency injection
- Enhanced documentation

### v1.0.0

[](#v100)

- Initial release with basic functionality

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance43

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

1434d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d702fe533aa6a71c5e6ef97e9b7033cd75365816747a9099ee19b103b1791630?d=identicon)[Hein-Thu-Ya](/maintainers/Hein-Thu-Ya)

---

Top Contributors

[![Hein-Thu-Ya](https://avatars.githubusercontent.com/u/32507388?v=4)](https://github.com/Hein-Thu-Ya "Hein-Thu-Ya (3 commits)")

### Embed Badge

![Health badge](/badges/centralbank-exchangerates/health.svg)

```
[![Health](https://phpackages.com/badges/centralbank-exchangerates/health.svg)](https://phpackages.com/packages/centralbank-exchangerates)
```

###  Alternatives

[cubear/finder

Finder is a Drupal 8 module to help users find services which meet their criteria

404.2k](/packages/cubear-finder)

PHPackages © 2026

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