mehr-it / lara-countries
Extendable multilingual, countries list for Laravel
Installs: 1 411
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 2
Requires
- php: >=7.1
- ext-json: *
- laravel/framework: ^5.8|^6.0|^7.0|^8.0
- mehr-it/php-cache: ^1.0
- umpirsky/country-list: ^2.0
- umpirsky/language-list: ^1.1
Requires (Dev)
- orchestra/testbench: ^3.8|^4.0|^5.0|^6.0
- phpunit/phpunit: ^7.4|^8.0
This package is auto-updated.
Last update: 2024-10-20 00:14:55 UTC
README
Localized country and language list for Laravel with all ISO codes.
Country list contains following data:
- alpha-2 country code (ISO 3166-1)
- alpha-3 country code (ISO 3166-1)
- Country name (in all locales)
- Dialing code (eg. 49 for Germany)
Language list contaings following data:
- alpha-2 language code (ISO 639-1)
- Language name (in all locales)
Unlike many other packages, it does not use a hardcoded list but imports the selected data to the database. For faster performance the data is cached locally in PHP files which are synchronized via the central application cache.
This way you get best performance but are still free to edit data.
Installation
Install the package using composer. Laravel's package auto discovery will do the rest for you:
composer require mehr-it/lara-countries
Import country data
After installation you have to import data to the database: To import the country/language list, run following command:
artisan countries:import
artisan languages:import
This imports the country/language list. If you need any other locale than "en", you can import them using following command:
artisan countries:importLocale de
artisan languages:importLocale de
Usage
You can access country information using the Countries
facade:
// get country information
Countries::get('US');
// get country information with other locale than the application locale
Countries::get('US', 'de');
// check if country code exists
Countries::exists('US');
// list all countries
Countries::all();
// list all countries with other locale than the application locale
Countries::all('de');
// list all iso2 codes
Countries::allIso2Codes();
You can access language information using the Languages
facade:
// get language information
Languages::get('en');
// get language information with other locale than the application locale
Languages::get('en', 'de');
// check if language code exists
Languages::exists('US');
// list all languages
Languages::all();
// list all languages with other locale than the application locale
Languages::all('de');
// list all iso2 codes
Languages::allIso2Codes();