- 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 Laravel-specific dependencies and works as a standalone PHP library. For Laravel integration, you can publish config files or bind it to the service container.
- Which Laravel versions does this package support?
- The package is framework-agnostic and works with any PHP 7.4+ project, including Laravel 8.x, 9.x, and 10.x. No Laravel-specific version constraints are enforced, but ensure your PHP version matches Laravel’s requirements.
- Can I use this package to populate a database table for currencies?
- Yes. The package provides CSV and JSON exports, making it easy to seed a database table. You can create a `Currency` model and use the package’s data in a seeder class (e.g., `CurrencySeeder`) to initialize your table.
- Does this package support dynamic currency updates (e.g., ISO 4217 changes)?
- The package ships with static data, so updates require manual intervention. For dynamic updates, you could extend the package to fetch the latest ISO 4217 data via their official API or a cron job, then merge it with the existing dataset.
- How do I display currency names/symbols in Blade templates?
- You can create a helper function or facade to access the data. For example, add a `Currency` facade in `app/Providers/AppServiceProvider` and use it in Blade like `@currency('EUR', 'en')` to display the Euro name in English.
- What if my app needs only a subset of locales (e.g., EU languages)?
- The package includes all supported locales by default, but you can filter the data in your application logic. For example, load only `['en', 'de', 'fr']` locales when initializing the package or query the data array programmatically.
- Are there alternatives to this package for Laravel currency data?
- Yes. Alternatives include `moneyphp/money` (for financial calculations) or `laravel-money/laravel-money` (Laravel-specific). However, those focus on monetary operations, while `umpirsky/currency-list` specializes in localized names/symbols for display purposes.
- How do I cache currency data for better performance?
- Cache the loaded currency data using Laravel’s cache system. For example, wrap the data fetch in `cache()->remember()` with a tag (e.g., `currencies`) to invalidate it when updates occur. This avoids reloading the dataset on every request.
- Does this package include validation for currency codes (e.g., ISO 4217 compliance)?
- The package provides accurate ISO 4217 codes, but validation logic (e.g., rejecting invalid codes) must be implemented in your application. You can extend the package or create a service layer to add custom validation rules.
- How do I test this package in my Laravel application?
- Test the package by verifying ISO codes, locale-specific names, and symbols. Use PHPUnit to assert data integrity (e.g., `assertEquals('Euro', CurrencyList::get('en')->get('EUR')->name)`). For localization, test edge cases like missing translations or unsupported locales.