- How do I install alcohol/iso4217 in a Laravel project?
- Run `composer require alcohol/iso4217` in your project root. No Laravel-specific setup is required—just instantiate the class directly in controllers, services, or commands. For dependency injection, bind it in `AppServiceProvider` using the service container.
- Does this package work with Laravel validation rules?
- Yes. Use it to validate currency codes in FormRequests by checking against `getByAlpha3()` or `getByNumeric()`. For example, add a custom rule to verify a field matches a valid ISO 4217 code before processing payments or transactions.
- What Laravel versions and PHP versions are supported?
- The package requires PHP 8.0+. Laravel 9+ is recommended (PHP 8.1+), but it works with any Laravel 8+ app running PHP 8.0+. For Laravel 7 or PHP 7.x, you’ll need to fork the package or use a polyfill.
- How often is the ISO 4217 data updated in this package?
- The data is static and shipped with the package. Updates require a `composer update`. For real-time needs, consider wrapping this library in a service that periodically syncs with an official ISO 4217 API or database.
- Can I cache the full currency list to improve performance?
- Yes. The `getAll()` method loads all currencies into memory. Cache the result using Laravel’s cache system, like `Cache::remember('iso4217.all', now()->addHours(24), fn() => $iso4217->getAll())`, to avoid repeated disk I/O or memory overhead.
- Are there any excluded currencies I should know about?
- The package excludes funds codes (e.g., BOV, XDR), commodity codes (XAU for gold), and deprecated currencies (e.g., ZWL for Zimbabwean dollar). If your app needs these, you’ll need to extend the library or use a different source.
- How can I use this in a Laravel API response or GraphQL resolver?
- For REST APIs, return currency data directly from `getByAlpha3()` or `getAll()`. In GraphQL, create a resolver that queries the library and returns structured data. Example: `return $iso4217->getByAlpha3($code);`. Pair with Laravel’s JSON responses for consistency.
- Is there a way to integrate this with Laravel’s localization system?
- The package provides English currency names only. For localized apps, extend the library to merge with Laravel’s language files or use a translation service. Example: Override `name` in the returned array with `__($currency['name'])` in your Blade or API responses.
- What happens if I pass an invalid currency code like 'XYZ'?
- The library throws an `InvalidCurrencyCodeException`. Handle it with a try-catch block or pre-validate codes using Laravel’s `Rule::exists()` or a custom validation rule. Example: `Rule::exists('iso4217', 'alpha3')->where('alpha3', $request->currency_code).`
- Are there alternatives if I need more features like real-time updates or custom currencies?
- For real-time updates, consider packages like `spatie/iso4217` (if available) or build a custom wrapper around the [ISO 4217 API](https://www.currency-iso.org/). For custom currencies, extend the class or use a database-backed solution like `laravel-currency` with seedable data.