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.
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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
php Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
