- What is bradietilley/country-enums and what problem does it solve?
- It is a PHP package that provides countries and their regions as native PHP enums, so you can reference countries as typed cases instead of maintaining your own arrays or loose strings. The helper methods make it easier to work with country codes, names, and related lookups. This improves autocomplete, reduces typos, and keeps country data consistent across your application.
- How do I install bradietilley/country-enums in a Laravel application?
- Install it with Composer using composer require bradietilley/country-enums. Because it is a PHP package built around enums, it can be used in Laravel and plain PHP projects. If the package registers a service provider or publishes configuration, Laravel's package discovery will usually handle the provider, but check the README for any additional setup steps.
- Which PHP and Laravel versions does this package require?
- The package relies on native PHP enums, so you need PHP 8.1 or newer. For Laravel, use a version that is compatible with that PHP requirement. Always check the package's composer.json or README for the exact version constraints before adding it to an existing project.
- How do I get a country's name or ISO code from the enum?
- You reference the enum case for the country and use the package's helper methods or properties to retrieve its name and code. The README documents the exact method names and available values. Because each country is a native enum case, your IDE can autocomplete the available countries as you type.
- Can I use these country enums outside Laravel in a plain PHP project?
- Yes. The package is installed through Composer and is based on PHP enums, so it works in any PHP 8.1+ project. Any Laravel-specific conveniences are optional, and you can reference the enum cases directly in plain PHP code.
- How should I store country enum values in a database?
- A common approach is to store the country's ISO code as a string column and convert between the database value and the enum in your application. Use the enum cases for validation instead of raw strings so invalid country values are rejected early. Check whether the enum is backed and persist its backed value where appropriate.
- Does the package include regions within countries, and how are they represented?
- The package overview states that countries and their regions are formatted as PHP enums. Regions are represented as typed enum cases associated with a country, letting you reference subdivisions without maintaining your own lists. Consult the README for the exact naming and structure of the region enums.
- How can I list all countries for a select dropdown?
- You can use the native cases() method on the country enum to retrieve all cases, then map each case to a label using the package's name helper. For a dropdown, build an array of stored value to display label from those cases. If the package provides additional collection helpers, the README will show the recommended approach.
- Is bradietilley/country-enums suitable for production use?
- It is a lightweight data-focused package, so the main production considerations are data completeness and how often updates are released. Review the repository's release history and Composer constraints before adopting it, and pin a version in your lock file. Running your application's test suite after installation will confirm compatibility with your Laravel and PHP versions.
- What are the alternatives to using a country enum package?
- Alternatives include maintaining your own country arrays or configuration files, using a broader country-data package, or relying on Laravel validation rules with ISO codes. The enum approach stands out for type safety, IDE autocomplete, and avoiding duplicated lists. Choose based on whether native enums fit your codebase and how much you want the package to manage country and region data.