|
1 |
| -# Forex for Laravel |
| 1 | +# Laravel Forex |
2 | 2 |
|
3 |
| -[](https://packagist.org/packages/elegantly/laravel-forex) |
4 |
| -[](https://github.com/ElegantEngineeringTech/laravel-forex/actions?query=workflow%3Arun-tests+branch%3Amain) |
5 |
| -[](https://github.com/ElegantEngineeringTech/laravel-forex/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain) |
| 3 | +[](https://packagist.org/packages/elegantly/laravel-forex) |
| 4 | +[](https://github.com/ElegantEngineeringTech/laravel-forex/actions?query=workflow%3Arun-tests+branch%3Amain) |
| 5 | +[](https://github.com/ElegantEngineeringTech/laravel-forex/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain) |
6 | 6 | [](https://packagist.org/packages/elegantly/laravel-forex)
|
7 | 7 |
|
8 |
| -Easily retreive latest exchange rates value in your app. |
| 8 | +**Laravel Forex** is a simple and flexible package for retrieving the latest and historical foreign exchange rates in your Laravel application. |
9 | 9 |
|
10 |
| -By default, this package use the free endpoint provided by [exchangerate-api.com](https://www.exchangerate-api.com/) but you can use it with any forex provider. |
| 10 | +By default, it uses the free tier from [exchangerate-api.com](https://www.exchangerate-api.com/), but you can easily configure it to use any other Forex provider. |
11 | 11 |
|
12 |
| -## Installation |
| 12 | +--- |
13 | 13 |
|
14 |
| -You can install the package via composer: |
| 14 | +## 🚀 Installation |
| 15 | + |
| 16 | +Install via Composer: |
15 | 17 |
|
16 | 18 | ```bash
|
17 | 19 | composer require elegantly/laravel-forex
|
18 | 20 | ```
|
19 | 21 |
|
20 |
| -You can publish the config file with: |
| 22 | +Publish the configuration file: |
21 | 23 |
|
22 | 24 | ```bash
|
23 |
| -php artisan vendor:publish --tag="laravel-forex-config" |
| 25 | +php artisan vendor:publish --tag="forex-config" |
24 | 26 | ```
|
25 | 27 |
|
26 |
| -This is the contents of the published config file: |
| 28 | +--- |
27 | 29 |
|
28 |
| -```php |
| 30 | +## ⚙️ Configuration |
| 31 | + |
| 32 | +Here’s the default configuration that will be published to `config/forex.php`: |
29 | 33 |
|
| 34 | +```php |
30 | 35 | use Elegantly\Forex\Integrations\ExchangeRateApiFree\ExchangeRateApiFreeConnector;
|
31 | 36 |
|
32 | 37 | return [
|
33 | 38 |
|
34 | 39 | 'cache' => [
|
35 | 40 | 'enabled' => true,
|
36 | 41 | 'driver' => env('FOREX_CACHE_DRIVER', env('CACHE_DRIVER', 'file')),
|
37 |
| - 'expiry_seconds' => 86_400, |
| 42 | + 'expiry_seconds' => 86_400, // 1 day |
38 | 43 | ],
|
39 | 44 |
|
40 | 45 | 'rate_limit' => [
|
41 | 46 | 'enabled' => false,
|
42 | 47 | 'driver' => env('FOREX_RATE_LIMIT_DRIVER', env('CACHE_DRIVER', 'file')),
|
43 |
| - 'every_seconds' => 3_600, |
| 48 | + 'every_seconds' => 3_600, // 1 hour |
44 | 49 | ],
|
45 | 50 |
|
46 | 51 | 'client' => ExchangeRateApiFreeConnector::class,
|
47 | 52 |
|
| 53 | + 'clients' => [ |
| 54 | + 'exchange-rate-api' => [ |
| 55 | + 'token' => env('EXCHANGE_RATE_API_TOKEN'), |
| 56 | + ], |
| 57 | + ], |
| 58 | + |
48 | 59 | ];
|
49 | 60 | ```
|
50 | 61 |
|
51 |
| -## Usage |
| 62 | +--- |
| 63 | + |
| 64 | +## 📦 Usage |
| 65 | + |
| 66 | +### Get Latest Rates |
52 | 67 |
|
53 | 68 | ```php
|
| 69 | +use Elegantly\Forex\Facades\Forex; |
| 70 | + |
| 71 | +$rates = Forex::latest('USD'); |
| 72 | + |
| 73 | +$usdToEur = $rates['EUR']; |
| 74 | +``` |
54 | 75 |
|
55 |
| -$rates = \Elegantly\Forex\Facades\Forex::get('USD'); |
| 76 | +### Get Historical Rates |
56 | 77 |
|
57 |
| -$USD_to_EUR_rate = $rates['EUR']; |
| 78 | +```php |
| 79 | +use Carbon\Carbon; |
| 80 | +use Elegantly\Forex\Facades\Forex; |
| 81 | + |
| 82 | +$rates = Forex::rates(Carbon::create(2022, 4, 25), 'USD'); |
58 | 83 |
|
| 84 | +$usdToEur = $rates['EUR']; |
59 | 85 | ```
|
60 | 86 |
|
61 |
| -## Testing |
| 87 | +--- |
| 88 | + |
| 89 | +## ✅ Testing |
| 90 | + |
| 91 | +Run the test suite with: |
62 | 92 |
|
63 | 93 | ```bash
|
64 | 94 | composer test
|
65 | 95 | ```
|
66 | 96 |
|
67 |
| -## Changelog |
| 97 | +--- |
| 98 | + |
| 99 | +## 📄 Changelog |
| 100 | + |
| 101 | +See the [CHANGELOG](CHANGELOG.md) for details on recent updates. |
68 | 102 |
|
69 |
| -Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. |
| 103 | +--- |
70 | 104 |
|
71 |
| -## Contributing |
| 105 | +## 🤝 Contributing |
72 | 106 |
|
73 |
| -Please see [CONTRIBUTING](CONTRIBUTING.md) for details. |
| 107 | +Contributions are welcome! Please read the [CONTRIBUTING](CONTRIBUTING.md) guide for details. |
74 | 108 |
|
75 |
| -## Security Vulnerabilities |
| 109 | +--- |
76 | 110 |
|
77 |
| -Please review [our security policy](../../security/policy) on how to report security vulnerabilities. |
| 111 | +## 🔐 Security |
78 | 112 |
|
79 |
| -## Credits |
| 113 | +If you discover any security-related issues, please refer to our [security policy](../../security/policy). |
| 114 | + |
| 115 | +--- |
| 116 | + |
| 117 | +## 🙏 Credits |
80 | 118 |
|
81 | 119 | - [Quentin Gabriele](https://github.com/QuentinGab)
|
82 | 120 | - [All Contributors](../../contributors)
|
83 | 121 |
|
84 |
| -## License |
| 122 | +--- |
| 123 | + |
| 124 | +## 📃 License |
| 125 | + |
| 126 | +This package is open-source software licensed under the [MIT license](LICENSE.md). |
| 127 | + |
| 128 | +--- |
85 | 129 |
|
86 |
| -The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
| 130 | +Let me know if you'd like this version saved in a `README.md` file or if you want badges for other integrations! |
0 commit comments