PHPackages                             laravelgpt/country-code - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. laravelgpt/country-code

ActiveLibrary[Templating &amp; Views](/categories/templating)

laravelgpt/country-code
=======================

A comprehensive Laravel package for country codes, phone codes, ISO codes, flags, and regional data with multi-framework frontend support

v2.0.0(10mo ago)04MITPHPPHP ^8.2CI failing

Since Jun 21Pushed 10mo agoCompare

[ Source](https://github.com/laravelgpt/country-code)[ Packagist](https://packagist.org/packages/laravelgpt/country-code)[ RSS](/packages/laravelgpt-country-code/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (10)Versions (3)Used By (0)

LaravelGPT Country Code Package
===============================

[](#laravelgpt-country-code-package)

A comprehensive Laravel package for country codes, phone codes, ISO codes, flags, and regional data with multi-framework frontend support.

🌟 Features
----------

[](#-features)

### Core Features

[](#core-features)

- **200+ Countries** with complete information
- **Phone codes** and international dialing formats
- **ISO 3166-1** alpha-2 and alpha-3 codes
- **Unicode flag emojis** and SVG flag support
- **Continental and regional groupings**
- **UN membership** and independence status
- **Currency information** and timezone data
- **Population and geographic data**

### Frontend Framework Support

[](#frontend-framework-support)

- **Blade Components** (Default - No additional dependencies)
- **Livewire Components** (Requires `livewire/livewire`)
- **Vue.js Components** (Requires `vue` npm package)
- **React Components** (Requires `react` npm package)
- **Alpine.js Components** (Requires `alpinejs` npm package)

### Advanced Features

[](#advanced-features)

- **Interactive Country Maps** with Leaflet.js
- **Advanced Search** with filters and autocomplete
- **Statistics Dashboard** with charts and exports
- **Multi-language Support** (12+ languages)
- **API Rate Limiting** and caching
- **Regional Groupings** (EU, G7, G20, ASEAN, etc.)
- **Phone Number Validation** and formatting
- **Export Functionality** (JSON, CSV, PDF)

📋 Requirements
--------------

[](#-requirements)

### PHP Requirements

[](#php-requirements)

- **PHP**: 8.2 or higher
- **Laravel**: 10.x or 11.x

### Frontend Dependencies

[](#frontend-dependencies)

The package includes a `package.json` file with recommended frontend dependencies:

```
# Install frontend dependencies (optional)
npm install

# Or install specific frameworks as needed:
npm install alpinejs        # For Alpine.js components
npm install vue             # For Vue.js components
npm install react react-dom # For React components
npm install leaflet         # For interactive maps
npm install chart.js        # For statistics charts
```

🚀 Quick Installation
--------------------

[](#-quick-installation)

### Basic Installation (Blade Only)

[](#basic-installation-blade-only)

```
composer require laravelgpt/country-code
php artisan country-code:install
```

### Interactive Installation with Frontend Selection

[](#interactive-installation-with-frontend-selection)

```
php artisan country-code:install --interactive
```

### Installation with Specific Frontend Framework

[](#installation-with-specific-frontend-framework)

```
# Blade (Default - No additional dependencies)
php artisan country-code:install --frontend=blade

# Livewire (Requires livewire/livewire)
composer require livewire/livewire
php artisan country-code:install --frontend=livewire

# Vue.js (Requires vue npm package)
npm install vue
php artisan country-code:install --frontend=vue

# React (Requires react npm package)
npm install react react-dom
php artisan country-code:install --frontend=react

# Alpine.js (Requires alpinejs npm package)
npm install alpinejs
php artisan country-code:install --frontend=alpine

# All frameworks
npm install
php artisan country-code:install --frontend=all
```

### Advanced Installation Options

[](#advanced-installation-options)

```
# Install with all assets
php artisan country-code:install --publish-all

# Skip migrations
php artisan country-code:install --skip-migrations

# Skip seeding
php artisan country-code:install --skip-seeding

# Force installation without confirmation
php artisan country-code:install --force
```

📋 Manual Setup
--------------

[](#-manual-setup)

### 1. Publish Configuration

[](#1-publish-configuration)

```
php artisan vendor:publish --provider="Laravelgpt\CountryCode\CountryCodeServiceProvider" --tag="config"
```

### 2. Publish Migrations

[](#2-publish-migrations)

```
php artisan vendor:publish --provider="Laravelgpt\CountryCode\CountryCodeServiceProvider" --tag="migrations"
```

### 3. Run Migrations

[](#3-run-migrations)

```
php artisan migrate
```

### 4. Seed Database

[](#4-seed-database)

```
php artisan country-code:seed
```

### 5. Publish Frontend Assets

[](#5-publish-frontend-assets)

```
# Blade components (no dependencies required)
php artisan vendor:publish --provider="Laravelgpt\CountryCode\CountryCodeServiceProvider" --tag="views"

# Livewire components (requires livewire/livewire)
php artisan vendor:publish --provider="Laravelgpt\CountryCode\CountryCodeServiceProvider" --tag="livewire"

# Vue components (requires vue npm package)
php artisan vendor:publish --provider="Laravelgpt\CountryCode\CountryCodeServiceProvider" --tag="vue"

# React components (requires react npm package)
php artisan vendor:publish --provider="Laravelgpt\CountryCode\CountryCodeServiceProvider" --tag="react"

# Alpine.js components (requires alpinejs npm package)
php artisan vendor:publish --provider="Laravelgpt\CountryCode\CountryCodeServiceProvider" --tag="js"
```

🎨 Frontend Framework Usage
--------------------------

[](#-frontend-framework-usage)

### Blade Components (No Dependencies Required)

[](#blade-components-no-dependencies-required)

```

```

### Livewire Components (Requires `livewire/livewire`)

[](#livewire-components-requires-livewirelivewire)

```

```

### Vue.js Components (Requires `vue` npm package)

[](#vuejs-components-requires-vue-npm-package)

```

import CountrySelector from './vendor/country-code/vue/CountrySelector.vue'
import CountryFlag from './vendor/country-code/vue/CountryFlag.vue'
import PhoneInput from './vendor/country-code/vue/PhoneInput.vue'
import CountrySearch from './vendor/country-code/vue/CountrySearch.vue'

export default {
  components: {
    CountrySelector,
    CountryFlag,
    PhoneInput,
    CountrySearch
  },
  data() {
    return {
      selectedCountry: null,
      phoneNumber: ''
    }
  },
  methods: {
    handleCountrySelect(country) {
      this.selectedCountry = country
    }
  }
}

```

### React Components

[](#react-components)

```
import React, { useState } from 'react'
import CountrySelector from './vendor/country-code/react/CountrySelector'
import CountryFlag from './vendor/country-code/react/CountryFlag'
import PhoneInput from './vendor/country-code/react/PhoneInput'
import CountrySearch from './vendor/country-code/react/CountrySearch'

function CountryCodeExample() {
  const [selectedCountry, setSelectedCountry] = useState(null)
  const [phoneNumber, setPhoneNumber] = useState('')

  return (

  )
}

export default CountryCodeExample
```

### Alpine.js Components

[](#alpinejs-components)

```

      Choose a country...

function countryCodeApp() {
  return {
    countries: [],
    selectedCountry: null,

    init() {
      this.loadCountries()
    },

    async loadCountries() {
      const response = await fetch('/api/countries')
      this.countries = await response.json()
    },

    getCountryFlag(code) {
      const country = this.countries.find(c => c.iso_alpha2 === code)
      return country ? country.flag_emoji : ''
    },

    getCountryName(code) {
      const country = this.countries.find(c => c.iso_alpha2 === code)
      return country ? country.name : ''
    }
  }
}

```

🔧 Backend Usage
---------------

[](#-backend-usage)

### Using the Facade

[](#using-the-facade)

```
use Laravelgpt\CountryCode\Facades\CountryCode;

// Get all countries
$countries = CountryCode::all();

// Find country by ISO code
$country = CountryCode::findByIso('US');

// Find country by phone code
$country = CountryCode::findByPhoneCode('1');

// Search countries
$results = CountryCode::search('United');

// Get countries by continent
$europeanCountries = CountryCode::getByContinent('Europe');

// Get countries by region
$westernCountries = CountryCode::getByRegion('Western Europe');

// Get UN member countries
$unMembers = CountryCode::getUnMembers();

// Get independent countries
$independent = CountryCode::getIndependent();

// Get default country
$default = CountryCode::getDefaultCountry();

// Validate country code
$isValid = CountryCode::validate('US');

// Get statistics
$stats = CountryCode::getStats();
```

### Using the Model

[](#using-the-model)

```
use Laravelgpt\CountryCode\Models\Country;

// Find country by ISO
$country = Country::where('iso_alpha2', 'US')->first();

// Get phone code
echo $country->phone_code; // 1

// Get flag emoji
echo $country->flag_emoji; // 🇺🇸

// Get country name
echo $country->name; // United States

// Get region
echo $country->region; // North America

// Get continent
echo $country->continent; // Americas
```

### Validation Rule

[](#validation-rule)

```
use Laravelgpt\CountryCode\Rules\ValidCountryCode;

$request->validate([
    'country_code' => ['required', new ValidCountryCode],
]);
```

### API Endpoints

[](#api-endpoints)

```
// Get all countries
GET /api/countries

// Get specific country
GET /api/countries/{code}

// Search countries
GET /api/countries/search?q=United

// Get countries by phone code
GET /api/countries/phone/{phoneCode}

// Get countries by continent
GET /api/countries/continent/{continent}

// Get countries by region
GET /api/countries/region/{region}

// Get all continents
GET /api/countries/continents

// Get all regions
GET /api/countries/regions

// Validate country code
POST /api/countries/validate

// Get statistics
GET /api/countries/stats
```

⚙️ Configuration
----------------

[](#️-configuration)

### Environment Variables

[](#environment-variables)

```
# Default country
COUNTRY_CODE_DEFAULT=US

# Cache settings
COUNTRY_CODE_CACHE_ENABLED=true
COUNTRY_CODE_CACHE_TTL=86400
COUNTRY_CODE_CACHE_PREFIX=country_code

# API settings
COUNTRY_CODE_API_ENABLED=true
COUNTRY_CODE_API_RATE_LIMIT=100
COUNTRY_CODE_API_TIMEOUT=30

# Frontend framework
COUNTRY_CODE_FRONTEND=blade
COUNTRY_CODE_LIVEWIRE_ENABLED=false
COUNTRY_CODE_VUE_ENABLED=false
COUNTRY_CODE_REACT_ENABLED=false
COUNTRY_CODE_ALPINE_ENABLED=false

# Phone number format
COUNTRY_CODE_PHONE_FORMAT=international

# Flag type
COUNTRY_CODE_FLAG_TYPE=emoji

# Database settings
COUNTRY_CODE_TABLE_NAME=countries
COUNTRY_CODE_AUTO_MIGRATE=true
COUNTRY_CODE_AUTO_SEED=true

# Logging
COUNTRY_CODE_LOGGING_ENABLED=true
COUNTRY_CODE_LOG_CHANNEL=daily
COUNTRY_CODE_LOG_LEVEL=info

# Development
COUNTRY_CODE_DEBUG=false
COUNTRY_CODE_PROFILING=false
COUNTRY_CODE_TESTING=false
```

### Configuration File

[](#configuration-file)

The package configuration file (`config/country-code.php`) contains comprehensive settings for:

- Default country
- Supported languages
- Cache configuration
- API settings
- Frontend framework configuration
- Regional groupings
- Phone number configuration
- Flag configuration
- Database settings
- Security settings
- Logging configuration
- Performance optimization
- Customization paths
- Development settings

🛠️ Available Commands
---------------------

[](#️-available-commands)

### Installation Commands

[](#installation-commands)

```
# Interactive installation
php artisan country-code:install --interactive

# Install with specific frontend
php artisan country-code:install --frontend=vue

# Install with all assets
php artisan country-code:install --publish-all
```

### Setup Commands

[](#setup-commands)

```
# Setup frontend framework
php artisan country-code:setup-frontend --framework=vue

# Interactive frontend setup
php artisan country-code:setup-frontend --interactive
```

### Asset Commands

[](#asset-commands)

```
# Publish all assets
php artisan country-code:publish-assets --frontend=all

# Publish specific framework assets
php artisan country-code:publish-assets --frontend=vue

# Force overwrite existing files
php artisan country-code:publish-assets --force
```

### Database Commands

[](#database-commands)

```
# Seed countries
php artisan country-code:seed

# Seed with confirmation
php artisan country-code:seed --confirm
```

📊 Statistics and Analytics
--------------------------

[](#-statistics-and-analytics)

### Built-in Statistics

[](#built-in-statistics)

- Total countries count
- Countries by continent
- Countries by region
- Phone code distribution
- Regional groupings
- Export functionality (JSON, CSV, PDF)

### Custom Analytics

[](#custom-analytics)

```
// Get continent statistics
$continentStats = CountryCode::getContinentStats();

// Get region statistics
$regionStats = CountryCode::getRegionStats();

// Get phone code statistics
$phoneStats = CountryCode::getPhoneStats();

// Get custom groupings
$euCountries = CountryCode::getByRegionalGroup('eu');
$g7Countries = CountryCode::getByRegionalGroup('g7');
```

🔒 Security Features
-------------------

[](#-security-features)

### Rate Limiting

[](#rate-limiting)

- Configurable API rate limiting
- Per-user and per-IP limits
- Customizable decay periods

### CORS Support

[](#cors-support)

- Configurable CORS settings
- Allowed origins, methods, and headers
- Secure by default

### Authentication

[](#authentication)

- Optional authentication requirements
- Configurable guards and middleware
- Role-based access control

🚀 Performance Optimization
--------------------------

[](#-performance-optimization)

### Caching

[](#caching)

- Intelligent caching system
- Configurable TTL and prefixes
- Cache invalidation strategies

### Database Optimization

[](#database-optimization)

- Eager loading support
- Query optimization
- Database indexes
- Pagination support

### Asset Optimization

[](#asset-optimization)

- Minified JavaScript and CSS
- Optimized component loading
- Tree-shaking support

🧪 Testing
---------

[](#-testing)

### Running Tests

[](#running-tests)

```
# Run all tests
php artisan test

# Run specific test suite
php artisan test --filter=CountryCodeTest

# Run with coverage
php artisan test --coverage
```

### Test Examples

[](#test-examples)

```
// Test facade functionality
$this->assertNotNull(CountryCode::findByIso('US'));

// Test validation rule
$this->assertTrue((new ValidCountryCode)->passes('country', 'US'));

// Test API endpoints
$this->get('/api/countries')->assertStatus(200);
```

📚 Examples and Documentation
----------------------------

[](#-examples-and-documentation)

### Example Files

[](#example-files)

After installation, example files are created in:

- `resources/views/examples/country-code/blade-example.blade.php`
- `resources/views/examples/country-code/livewire-example.blade.php`
- `resources/js/examples/vue-example.js`
- `resources/js/examples/react-example.jsx`
- `resources/views/examples/country-code/alpine-example.blade.php`

### Documentation

[](#documentation)

- [API Documentation](https://github.com/laravelgpt/country-code/wiki/API)
- [Component Documentation](https://github.com/laravelgpt/country-code/wiki/Components)
- [Configuration Guide](https://github.com/laravelgpt/country-code/wiki/Configuration)
- [Frontend Integration](https://github.com/laravelgpt/country-code/wiki/Frontend)

🤝 Contributing
--------------

[](#-contributing)

We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.

### Development Setup

[](#development-setup)

```
# Clone the repository
git clone https://github.com/laravelgpt/country-code.git

# Install dependencies
composer install

# Run tests
php artisan test

# Run linting
./vendor/bin/pint
```

📄 License
---------

[](#-license)

This package is open-sourced software licensed under the [MIT License](LICENSE.md).

🆘 Support
---------

[](#-support)

- **Documentation**: [GitHub Wiki](https://github.com/laravelgpt/country-code/wiki)
- **Issues**: [GitHub Issues](https://github.com/laravelgpt/country-code/issues)
- **Discussions**: [GitHub Discussions](https://github.com/laravelgpt/country-code/discussions)
- **Email**:

🎯 Roadmap
---------

[](#-roadmap)

### Upcoming Features

[](#upcoming-features)

- GeoJSON country boundaries
- Advanced mapping features
- Real-time data updates
- Mobile app support
- GraphQL API
- Machine learning integration
- Advanced analytics dashboard
- Multi-tenant support
- API versioning
- Webhook support

### Version History

[](#version-history)

- **v2.0.0**: Multi-framework support, interactive maps, advanced statistics
- **v1.0.0**: Initial release with basic functionality

---

**Made with ❤️ by the LaravelGPT Team**

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance56

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

321d ago

Major Versions

v1.0 → v2.0.02025-06-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/ad107e973e4942f97e875f216484319e0d23e1a354ceae083f627715759c7096?d=identicon)[laravelgpt](/maintainers/laravelgpt)

---

Top Contributors

[![laravelgpt](https://avatars.githubusercontent.com/u/21008964?v=4)](https://github.com/laravelgpt "laravelgpt (4 commits)")

---

Tags

laravelcomponentsisophonebladelivewirereactflaggeographyfrontendcountryalpinevueregional

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/laravelgpt-country-code/health.svg)

```
[![Health](https://phpackages.com/badges/laravelgpt-country-code/health.svg)](https://phpackages.com/packages/laravelgpt-country-code)
```

###  Alternatives

[robsontenorio/mary

Gorgeous UI components for Livewire powered by daisyUI and Tailwind

1.5k454.7k15](/packages/robsontenorio-mary)[mati365/ckeditor5-livewire

CKEditor 5 integration for Laravel Livewire

413.9k](/packages/mati365-ckeditor5-livewire)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
