1. Go to this page and download the library: Download jszdavid/laravel-world 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/ */
use JSzD\World\Facades\World;
// Get all countries (default fields: id, name, iso2)
$countries = World::countries([])->data;
// Get countries with specific fields and search
$countries = World::countries([
'fields' => 'id,name,iso2,phone_code',
'search' => 'United',
])->data;
// Filter countries
$countries = World::countries([
'filters' => [
'iso2' => 'US'
]
])->data;
// Get states for a country
$states = World::states([
'filters' => [
'country_code' => 'US'
]
])->data;
// Get cities for a state
$cities = World::cities([
'filters' => [
'state_id' => 123
]
])->data;
// Get cities for a country
$cities = World::cities([
'filters' => [
'country_code' => 'US'
]
])->data;