Installation Guide
Get started with Laravel Countries in your Laravel application.
Requirements
Requirement
|
Version
|
Status
|
---|---|---|
PHP | 8.2+ | |
Laravel | ^11.0 | ^12.0 | |
Database | MySQL, PostgreSQL, SQLite, SQL Server |
Installation Steps
Step 1: Install via Composer
Install the package using Composer:
composer require webpatser/laravel-countries
Step 2: Run the Installer
Use the interactive installer to set up the database and configuration:
php artisan countries:install
The installer will:
- Ask for your preferred database table name (defaults to
countries
) - Generate and run database migrations
- Import all 249 countries with flags, currencies, and regional data
- Publish the configuration file
- Display all country flags to verify successful installation
Manual Installation
If you prefer to set up the package manually:
Publish Configuration
php artisan vendor:publish --tag=countries-config
Generate and Run Migrations
php artisan countries:migrationphp artisan migrate
Seed the Database
php artisan db:seed --class=CountriesSeeder
Configuration
The configuration file is published to config/countries.php
:
return [ /* |-------------------------------------------------------------------------- | Database Table Name |-------------------------------------------------------------------------- */ 'table_name' => 'countries', /* |-------------------------------------------------------------------------- | Cache Settings |-------------------------------------------------------------------------- */ 'cache_ttl' => 0, // Disable caching (recommended for database source) /* |-------------------------------------------------------------------------- | Data Source |-------------------------------------------------------------------------- */ 'data_source' => 'database', // 'database' or 'json' /* |-------------------------------------------------------------------------- | Default Sort Field |-------------------------------------------------------------------------- */ 'default_sort' => 'name', /* |-------------------------------------------------------------------------- | Localization |-------------------------------------------------------------------------- */ 'localized' => false, /* |-------------------------------------------------------------------------- | Search Settings |-------------------------------------------------------------------------- */ 'search' => [ 'fields' => ['name', 'capital'], 'case_sensitive' => false, ],];
Verify Installation
Test your installation with this simple code:
use Webpatser\Countries\Countries; $countries = new Countries();$usa = $countries->getOne('US'); echo $usa['name']; // "United States"echo $usa['flag']; // "πΊπΈ"
Installation Working!
Laravel Countries is properly installed and functioning.
Quick Tests:
πΊπΈ
United States of America
US
Capital:
Washington, D.C.
Region:
americas
Currency:
$ USD
Test Code Example:
use Webpatser\Countries\Countries; $countries = new Countries(); $country = $countries->getOne('US'); echo $country['name']; // "United States of America" echo $country['flag']; // "πΊπΈ" echo $country['capital']; // "Washington, D.C."
Troubleshooting
Common Issues
Package Not Found
If Composer cannot find the package, ensure you have added the correct repository or the package has been published to Packagist.