Using the laravel-currency Package to Retrieve Daily Exchange Rates in Laravel

This article explains how to use the free laravel-currency extension, which leverages the European Central Bank API, to obtain real‑time and historical exchange rates for CNY, USD, and JPY in Laravel applications, including installation steps and practical code examples.

php Courses
php Courses
php Courses
Using the laravel-currency Package to Retrieve Daily Exchange Rates in Laravel

This article introduces the laravel-currency package, which uses the European Central Bank API to provide free real‑time and historical exchange rates for currencies such as CNY, USD, and JPY.

The package is easy to integrate into a Laravel project; the README contains detailed usage examples. Below are the most common scenarios.

// Get the current exchange rate from USD to CNY
Currency::convert()->from('USD')->to('CNY')->get();
// Convert 100 USD to CNY using the current rate
Currency::convert()->from('USD')->to('CNY')->amount(100)->get();
// Use the rate from a specific date (e.g., 2020‑05‑10) to convert 100 USD to CNY
Currency::convert()->from('USD')->to('CNY')->amount(100)->date('2020-05-10')->get();

Developers interested in currency conversion can follow the link to the GitHub repository, try the examples, or share other useful Laravel extensions.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CurrencyLaravelExchangeRate
php Courses
Written by

php Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.