Package Data | |
---|---|
Maintainer Username: | nnjeim |
Maintainer Contact: | najm@njeim.net (Najm Njeim) |
Package Create Date: | 2021-10-25 |
Package Last Update: | 2025-02-07 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-02-09 15:18:01 |
Package Statistics | |
---|---|
Total Downloads: | 130,797 |
Monthly Downloads: | 9,101 |
Daily Downloads: | 86 |
Total Stars: | 791 |
Total Watchers: | 13 |
Total Forks: | 113 |
Total Open Issues: | 3 |
A Laravel package to provide a list of the countries, 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)
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 | array* containing (string) fields* and (array) filters* | | states | lists all the states | array* containing (string) fields* and (array) filters* | | cities | lists all the cities | array* containing (string) fields* and (array) filters* | | timezones | lists all the timezones | array* containing (string) fields* and (array) filters* | | currencies | lists all the currencies | array* containing (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
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
composer test
Please see CHANGELOG for more information what has changed recently.
* optional