- How do I install umpirsky/currency-list in a Laravel project?
- Run `composer require umpirsky/currency-list` in your project root. The package has no dependencies and works standalone. For Laravel, you can register it as a service provider or use it directly via `CurrencyList::get('en')` for English currency names.
- Which Laravel versions does this package support?
- The package is PHP-only and works with Laravel 5.5+ (or any PHP 7.2+ project). No Laravel-specific dependencies mean it’s framework-agnostic, but the examples in the docs assume Laravel 8+ conventions like service providers and facades.
- Can I use this for dynamic currency dropdowns in a multi-language app?
- Yes. The package provides localized currency names and symbols for over 100 languages. Fetch data like `CurrencyList::get('es')` for Spanish names, then loop through the array in Blade or a frontend framework. Cache the results for performance.
- How do I update currency data if ISO 4217 changes?
- The package ships with static data files. For updates, check the GitHub repo for new releases or manually replace the `data/` directory with the latest CLDR-based files. Automate this by writing a script to fetch ISO updates and regenerate the package’s data files.
- Is there a way to store currency data in my database instead of using the static files?
- Yes. Export the data to CSV/JSON via `CurrencyList::all()` and seed it into a `currencies` table. Use Laravel migrations to define columns like `code`, `name`, `symbol`, and `locale`. For updates, overwrite the table via a seeder or cron job.
- Does this package support currency validation (e.g., rejecting invalid ISO codes)?
- The package provides raw data, so validation is manual. Wrap it in a service class to add rules like `CurrencyService::validate('XYZ')` (returns false for invalid codes). For business logic (e.g., blacklisted currencies), extend the class or use Laravel’s Form Request validation.
- How do I cache currency data for better performance?
- Cache locale-specific data using Laravel’s cache driver. Example: `cache()->remember('currencies_en', now()->addDays(30), fn() => CurrencyList::get('en'))`. Use tagged caching (e.g., `cache()->tags(['currencies'])->put()`) to invalidate when data updates.
- Are there alternatives to this package for Laravel currency support?
- Yes. For API-based solutions, consider `spatie/currency` (uses an external API) or `moneyphp/money` (for financial calculations). For static data, `league/currency` is another option, but `umpirsky/currency-list` stands out for its CLDR-based localization and zero-dependency approach.
- How do I test this package in my Laravel app?
- Test edge cases like invalid ISO codes (e.g., `CurrencyList::get('XYZ')` should return null). For localization, verify translations for critical paths (e.g., `CurrencyList::get('fr')` for French). Mock the package in unit tests using PHPUnit’s `partialMock` or a data provider.
- Can I extend this package to include historical exchange rates?
- The package focuses on static metadata (names/symbols), not rates. For rates, pair it with an API like `exchangerate-api` or a database table for historical data. Use Laravel’s service container to combine both (e.g., `app()->make(CurrencyService::class)`).