Recommend this page to a friend! |
![]() |
Info | Documentation | ![]() |
![]() |
![]() |
Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not yet rated by the users | Total: 25 | All time: 11,257 This week: 455![]() |
Version | License | PHP version | Categories | |||
world 1.0 | Custom (specified... | 5 | PHP 5, Libraries, Geography |
Description | Author | |||||||||||||
This package can get data specific to world locations. |
|
<p><img src="https://eu.ui-avatars.com/api/?name=Najm+Njeim?size=100" width="100"/></p>
A Laravel package to provide a list of the countries, states, cities, timezones, currencies and phone numbers formatting/validation helpers.
The package can be consumed through Facades, Helpers and Api routes.
composer require nnjeim/world
php artisan vendor:publish --tag=world
php artisan migrate
php artisan db:seed --class=WorldSeeder (requires ~ 5 - 10min)
Please see CHANGELOG for more information what has changed recently.
use Nnjeim\World\World;
$action = World::countries();
if ($action->success) {
$countries = $action->data;
}
response
{
"success": true,
"message": "countries",
"data": [
{
"id": 1,
"name": "Afghanistan"
},
{
"id": 2,
"name": "Ã…land Islands"
},
.
.
.
],
}
use Nnjeim\World\World;
$action = World::countries([
'fields' => 'states,cities',
'filters' => [
'iso2' => 'FR',
]
]);
if ($action->success) {
$countries = $action->data;
}
response
{
"success": true,
"message": "countries",
"data": [
"id": 77,
"name": "France",
"states": [
{
"id": 1271,
"name": "Alo"
},
{
"id": 1272,
"name": "Alsace"
},
.
.
.
],
"cities": [
{
"id": 25148,
"name": "Abondance"
},
{
"id": 25149,
"name": "Abrest"
},
.
.
.
]
],
}
use Nnjeim\World\WorldHelper;
protected $world;
public function __construct(WorldHelper $world) {
$this->world = $world;
}
$action = $this->world->cities([
'filters' => [
'country_id' => 182,
],
]);
if ($action->success) {
$cities = $action->data;
}
| Name | Description | Argument* | | :--- | :--- |:--- | | countries | lists all the world countries | arraycontaining (string) fields and (array) filters* | | states | lists all the states | arraycontaining (string) fields and (array) filters* | | cities | lists all the cities | arraycontaining (string) fields and (array) filters* | | timezones | lists all the timezones | arraycontaining (string) fields and (array) filters* | | currencies | lists all the currencies | arraycontaining (string) fields and (array) filters* |
The methods' return is structured as below:
All routes can be prefixed by any string. Ex admin, api, v1 ...
| | | | :--- | :--- | | Method | GET | | Route | /{prefix}/countries | | Parameters* | comma seperated fields(countries table fields in addition to states, cities, currency and timezones), array filters | | Example | /v1/countries?fields=iso2,cities&filters[phone_code]=44 | | response | success, message, data |
| | | | :--- | :--- | | Method | GET | | Route | /{prefix}/states | | Parameters* | comma seperated fields(states table fields in addition to country and cities), array filters | | Example | /v1/states?fields=country,cities&filters[country_id]=182 | | response | success, message, data |
| | | | :--- | :--- | | Method | GET | | Route | /{prefix}/cities | | Parameters* | comma seperated fields(states table fields in addition to country and state), array filters | | Example | /v1/cities?fields=country,state&filters[country_id]=182 | | response | success, message, data |
| | | | :--- | :--- | | Method | GET | | Route | /{prefix}/timezones | | Parameters* | comma seperated fields(states table fields in addition to the country), array filters | | Example | /v1/timezones?fields=country&filters[country_id]=182 | | response | success, message, data |
| | | | :--- | :--- | | Method | GET | | Route | /{prefix}/timezones | | Parameters* | comma seperated fields(states table fields in addition to the country), array filters | | Example | /v1/timezones?fields=country&filters[country_id]=182 | | response | success, message, data |
| | | | :--- | :--- | | Method | POST | | Route | /{prefix}/phones/validate | | Parameters | key, value | | Example | /v1/phones/validate?number=060550987&phone_code=33 |
| | | | :--- | :--- | | Method | POST | | Route | /{prefix}/phones/strip | | Parameters | key, value | | Example | /v1/phones/strip?number=060550987&phone_code=33 |
| | | | :--- | :--- | | Method | POST | | Route | /{prefix}/phones/format | | Parameters | key, value | | Example | /v1/phones/format?number=060550987&phone_code=33 |
formatNumber($number, $phone_code = null);
ex. formatNumber('06 78 909 876', '33') returns +33 67 890 9876
stripNumber($number, $phone_code = null);
ex. stripNumber('06 78 909 876', '33') return 33678909876
if the argument $phone_code is not passed to the helpers, the used dialling code would be taken from
config('world.default_phone_code')
The available locales are ar, br, de, en, es, fr, ja, kr, pl, pt, ro, ru and zh. The default locale is en. Include in the request header
accept-language=locale
<p><img src="./schema.jpg" width="600px"/></p>
id, name, iso2, iso3, phone_code, dialling_pattern, region, sub_region, status
id, name, country_id
id, name, state_id, country_id
id, name, country_id
id, country_id, name, code, precision, symbol, symbol_native, symbol_first, decimal_mark, thousands_separator
Requirements - The database is seeded. - The database connection is defined in the .env file.
Browse to the package root folder and run:
composer install //installs the package dev dependencies
composer test
* optional
![]() |
File | Role | Description | ||
---|---|---|---|---|
![]() |
||||
![]() |
||||
![]() |
||||
![]() |
||||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Lic. | License text | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Doc. | Documentation | ||
![]() ![]() |
Data | Auxiliary data |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
![]() |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.