PHP code example of laravelgpt / country-code

1. Go to this page and download the library: Download laravelgpt/country-code library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

laravelgpt / country-code example snippets


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();

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

use Laravelgpt\CountryCode\Rules\ValidCountryCode;

$request->validate([
    'country_code' => ['

// 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

// 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');

// 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);
bash
php artisan country-code:install --interactive
bash
php artisan vendor:publish --provider="Laravelgpt\CountryCode\CountryCodeServiceProvider" --tag="config"
bash
php artisan vendor:publish --provider="Laravelgpt\CountryCode\CountryCodeServiceProvider" --tag="migrations"
bash
php artisan migrate
bash
php artisan country-code:seed
bash
# Setup frontend framework
php artisan country-code:setup-frontend --framework=vue

# Interactive frontend setup
php artisan country-code:setup-frontend --interactive
bash
# Seed countries
php artisan country-code:seed

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