Skip to main content
Back to packages
977 GitHub stars

nnjeim/world

View on GitHub

Description

Laravel package which provides a list of the countries, states, cities, timezones, currencies and languages.

List all the countries

Use the World facade:

use Nnjeim\World\World;
 
$action = World::countries();
 
if ($action->success) {
$countries = $action->data;
}
 
response (object)
{
"success": true,
"data": [
{
"id": 1,
"name": "Afghanistan"
},
{
"id": 2,
"name": "Åland Islands"
},
.
.
.
],
}

Use the API countries endpoint:

https://myDomain.local/api/countries

Fetch a country with its states and cities.

Use the World facade:

use Nnjeim\World\World;
 
$action = World::countries([
'fields' => 'states,cities',
'filters' => [
'iso2' => 'FR',
]
]);
 
if ($action->success) {
 
$countries = $action->data;
}

Response:

(object)
{
"success": true,
"data": [
"id": 77,
"name": "France",
"states": [
{
"id": 1271,
"name": "Alo"
},
{
"id": 1272,
"name": "Alsace"
},
.
.
.
],
"cities": [
{
"id": 25148,
"name": "Abondance"
},
{
"id": 25149,
"name": "Abrest"
},
.
.
.
]
],
}

Use the API countries endpoint:

https://myDomain.local/api/countries?fields=states,cities&filters[iso2]=FR

Recent Courses on Laravel Daily