Download the PHP package opheus2/laravel-countries without Composer
On this page you can find all versions of the php package opheus2/laravel-countries. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download opheus2/laravel-countries
More information about opheus2/laravel-countries
Files in opheus2/laravel-countries
Package laravel-countries
Short Description Get informations about countries and their currency.
License MIT
Homepage https://github.com/opheus2/laravel-countries
Informations about the package laravel-countries
Laravel Countries
A Laravel package that provides comprehensive data for every country — codes, names, currencies, languages, capitals, regions, demonyms, translations, and more. Laravel 11+ supported.
What's New in v3.0.0
- Updated data source — Country data is now compiled from the REST Countries v3.1 dataset.
- New search methods — Search by name, language, capital, demonym, translation, and independence status.
- Unified code lookup — New
getByCode()method auto-detects cca2, cca3, ccn3, or cioc codes. - Deprecations —
getByAlpha2Code(),getByAlpha3Code(), andgetByNumericCode()are deprecated in favor ofgetByCode(). They still work but will triggerE_USER_DEPRECATEDnotices. - PHPUnit 12 compatibility — Test suite updated.
Install
Upgrading from v2.x
Replace deprecated method calls:
The deprecated methods still function but will emit E_USER_DEPRECATED warnings and will be removed in a future major release.
Usage
Lookup by Code
The getByCode() method auto-detects the code type:
Search by Name
Search by Language
Search by Capital
Search by Demonym
Search by Translation
Search by Currency
Filter by Region / Subregion
Filter by Independence Status
Get All Countries
Dropdown List Helper
Country Object
Currency Object
Eloquent Cast
Store country references in your database and cast them automatically:
Macros
The Country class implements Laravel's Macroable trait:
Mixins
Raw Data Access
Configuration
Publish the config file to customize the data source:
This creates config/laravel-countries.php where you can point to a custom JSON file:
Data Source
Country data is compiled from the REST Countries v3.1 JSON dataset using the included compile script (scripts/compile-data-source.php).
Differences from upstream REST Countries v3.1
- Field mapping —
nativeNameis stored asnativeunder thenamekey. - Computed field —
callingCodesis computed fromidd.root+idd.suffixesfor convenience. - Translation subset — Only 26 translation languages are included (ara, bre, ces, cym, deu, est, fin, fra, hrv, hun, ind, ita, jpn, kor, nld, per, pol, por, rus, slk, spa, srp, swe, tur, urd, zho).
- Currency overrides — The following corrections are applied to upstream data:
- Cuba (CU) — CUC removed (convertible peso eliminated Jan 1, 2021), CUP only.
- Bouvet Island (BV) — NOK added (uninhabited Norwegian territory).
- Heard Island (HM) — AUD added (uninhabited Australian territory).
- Micronesia (FM) — USD added (sometimes missing upstream).
- Antarctica (AQ) — USD, GBP, EUR added (used at research stations).
Recompiling Data
To regenerate the data source from the latest upstream JSON:
API Reference
| Method | Returns | Description |
|---|---|---|
getByCode($code) |
Country\|null |
Lookup by cca2, cca3, ccn3, or cioc |
getByName($name) |
array |
Partial match on common/official/native names |
getByFullName($name) |
array |
Exact match on common or official name |
getByLanguage($language) |
array |
Search by language code or name |
getByCapital($capital) |
array |
Search by capital city (partial) |
getByDemonym($demonym) |
array |
Search by demonym (exact, case-insensitive) |
getByTranslation($translation) |
array |
Search any translation name (partial) |
getByCurrency($currency) |
array |
Search by currency code or name |
getByRegion($region) |
array |
Filter by region |
getBySubregion($subregion) |
array |
Filter by subregion |
getIndependent($status) |
array |
Filter by independence status |
getAll($codes, $asCollection) |
array\|Collection |
Get all or filtered countries |
getListForDropdown($key, $official, $locale) |
array |
Key-value pairs for dropdowns |
getRawData() |
array |
Raw country data array |
Deprecated Methods (v3.0.0)
| Deprecated Method | Replacement |
|---|---|
getByAlpha2Code($code) |
getByCode($code) |
getByAlpha3Code($code) |
getByCode($code) |
getByNumericCode($code) |
getByCode($code) |
Credits
- Orpheus — Maintainer and fork author.
- Patrick Samson — Original laravel-countries package.
- REST Countries — v3.1 country data source (compiled and adapted with overrides).
- Mohammed Le Doze — Previous data source via mledoze/countries.
- All Contributors
License
The MIT License (MIT). Please see License File for more information.