PHP Classes

Laravel World: Get data specific to world locations

Recommend this page to a friend!
  Info   View files Documentation   View files View files (99)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2021-11-08 (11 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 21 This week: 2All time: 10,421 This week: 115Up
Version License PHP version Categories
world 1.0Custom (specified...5PHP 5, Libraries, Geography
Description Author

This package can get data specific to world locations.

It provides models, views, controllers based on the Laravel framework to return several types of data of interest related to many locations of the world.

Currently, it provides information about countries, states, cities, currencies, and timezones.

Picture of NN
Name: NN <contact>
Classes: 1 package by
Country: United States United States

Details

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

Installation

composer require nnjeim/world

php artisan vendor:publish --tag=world

php artisan migrate

php artisan db:seed --class=WorldSeeder (requires ~ 5 - 10min)

Changelog

Please see CHANGELOG for more information what has changed recently.

Usage

World Facade

List all the countries.

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"
		},
		.
		.
		.
	],
}

Fetch a country with its states and cities.

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"
			},
			.
			.
			.
		]
	],
}

World Helper Class

List all the cities by country id.

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;
}

Available methods

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

  • success (boolean)
  • message (string)
  • data (instance of Illuminate\Support\Collection)
  • errors (array)

Countries method

  • fields*: comma seperated string(countries table fields in addition to states, cities, currency and timezones).
  • filters*: array of keys(countries table fields) and their correspondant values.

States method

  • fields*: comma seperated string(states table fields in addition to country and states).
  • filters*: array of keys(states table fields) and their correspondant values.

Cities method

  • fields*: comma seperated string(cities table fields in addition to country and state).
  • filters*: array of keys(cities table fields) and their correspondant values.

Timezones method

  • fields*: comma seperated string(timezones table fields in addition to country).
  • filters*: array of keys(timezones table fields) and their correspondant values.

Currencies method

  • fields*: comma seperated string(currencies table fields in addition to country).
  • filters*: array of keys(currencies table fields) and their correspondant values.

Available routes

All routes can be prefixed by any string. Ex admin, api, v1 ...

Countries

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

States

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

Cities

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

Timezones

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

Currencies

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

Validate Number

| | | | :--- | :--- | | Method | POST | | Route | /{prefix}/phones/validate | | Parameters | key, value | | Example | /v1/phones/validate?number=060550987&phone_code=33 |

Strip Number

| | | | :--- | :--- | | Method | POST | | Route | /{prefix}/phones/strip | | Parameters | key, value | | Example | /v1/phones/strip?number=060550987&phone_code=33 |

Format Number

| | | | :--- | :--- | | Method | POST | | Route | /{prefix}/phones/format | | Parameters | key, value | | Example | /v1/phones/format?number=060550987&phone_code=33 |

Helpers

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

Localization

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

Schema

<p><img src="./schema.jpg" width="600px"/></p>

Countries database table fields

id, name, iso2, iso3, phone_code, dialling_pattern, region, sub_region, status

States database table fields

id, name, country_id

Cities database table fields

id, name, state_id, country_id

Timezones database table fields

id, name, country_id

Currencies database table fields

id, country_id, name, code, precision, symbol, symbol_native, symbol_first, decimal_mark, thousands_separator

Testing

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

  Files folder image Files  
File Role Description
Files folder imageconfig (1 file)
Files folder imageresources (2 directories)
Files folder imagesrc (3 files, 7 directories)
Files folder imagetests (1 file, 1 directory)
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Image file schema.jpg Data Auxiliary data

  Files folder image Files  /  config  
File Role Description
  Accessible without login Plain text file world.php Aux. Auxiliary script

  Files folder image Files  /  resources  
File Role Description
Files folder imagejson (3 files)
Files folder imagelang (13 directories)

  Files folder image Files  /  resources  /  json  
File Role Description
  Accessible without login Plain text file countries.json Data Auxiliary data
  Accessible without login Plain text file currencies.json Data Auxiliary data
  Accessible without login Plain text file states.json Data Auxiliary data

  Files folder image Files  /  resources  /  lang  
File Role Description
Files folder imagear (2 files)
Files folder imagebr (2 files)
Files folder imagede (2 files)
Files folder imageen (2 files)
Files folder imagees (2 files)
Files folder imagefr (2 files)
Files folder imageja (2 files)
Files folder imagekr (2 files)
Files folder imagepl (2 files)
Files folder imagept (2 files)
Files folder imagero (2 files)
Files folder imageru (2 files)
Files folder imagezh (2 files)

  Files folder image Files  /  resources  /  lang  /  ar  
File Role Description
  Accessible without login Plain text file country.php Aux. Auxiliary script
  Accessible without login Plain text file response.php Aux. Auxiliary script

  Files folder image Files  /  resources  /  lang  /  br  
File Role Description
  Accessible without login Plain text file country.php Aux. Auxiliary script
  Accessible without login Plain text file response.php Aux. Auxiliary script

  Files folder image Files  /  resources  /  lang  /  de  
File Role Description
  Accessible without login Plain text file country.php Aux. Auxiliary script
  Accessible without login Plain text file response.php Aux. Auxiliary script

  Files folder image Files  /  resources  /  lang  /  en  
File Role Description
  Accessible without login Plain text file country.php Aux. Auxiliary script
  Accessible without login Plain text file response.php Aux. Auxiliary script

  Files folder image Files  /  resources  /  lang  /  es  
File Role Description
  Accessible without login Plain text file country.php Aux. Auxiliary script
  Accessible without login Plain text file response.php Aux. Auxiliary script

  Files folder image Files  /  resources  /  lang  /  fr  
File Role Description
  Accessible without login Plain text file country.php Aux. Auxiliary script
  Accessible without login Plain text file response.php Aux. Auxiliary script

  Files folder image Files  /  resources  /  lang  /  ja  
File Role Description
  Accessible without login Plain text file country.php Aux. Auxiliary script
  Accessible without login Plain text file response.php Aux. Auxiliary script

  Files folder image Files  /  resources  /  lang  /  kr  
File Role Description
  Accessible without login Plain text file country.php Aux. Auxiliary script
  Accessible without login Plain text file response.php Aux. Auxiliary script

  Files folder image Files  /  resources  /  lang  /  pl  
File Role Description
  Accessible without login Plain text file country.php Aux. Auxiliary script
  Accessible without login Plain text file response.php Aux. Auxiliary script

  Files folder image Files  /  resources  /  lang  /  pt  
File Role Description
  Accessible without login Plain text file country.php Aux. Auxiliary script
  Accessible without login Plain text file response.php Aux. Auxiliary script

  Files folder image Files  /  resources  /  lang  /  ro  
File Role Description
  Accessible without login Plain text file country.php Aux. Auxiliary script
  Accessible without login Plain text file response.php Aux. Auxiliary script

  Files folder image Files  /  resources  /  lang  /  ru  
File Role Description
  Accessible without login Plain text file country.php Aux. Auxiliary script
  Accessible without login Plain text file response.php Aux. Auxiliary script

  Files folder image Files  /  resources  /  lang  /  zh  
File Role Description
  Accessible without login Plain text file country.php Aux. Auxiliary script
  Accessible without login Plain text file response.php Aux. Auxiliary script

  Files folder image Files  /  src  
File Role Description
Files folder imageActions (3 files, 6 directories)
Files folder imageConsole (1 file)
Files folder imageDatabase (2 directories)
Files folder imageHelpers (1 file)
Files folder imageHttp (3 directories)
Files folder imageModels (5 files, 1 directory)
Files folder imageRoutes (1 file)
  Plain text file World.php Class Class source
  Plain text file WorldHelper.php Class Class source
  Plain text file WorldServiceProvider.php Class Class source

  Files folder image Files  /  src  /  Actions  
File Role Description
Files folder imageCity (1 file, 2 directories)
Files folder imageCountry (1 file, 2 directories)
Files folder imageCurrency (1 file, 2 directories)
Files folder imagePhone (3 files)
Files folder imageState (1 file, 2 directories)
Files folder imageTimezone (1 file, 2 directories)
  Plain text file ActionInterface.php Class Class source
  Plain text file BaseAction.php Class Class source
  Plain text file SeedAction.php Class Class source

  Files folder image Files  /  src  /  Actions  /  City  
File Role Description
Files folder imageQueries (1 file)
Files folder imageTransformers (1 file)
  Plain text file IndexAction.php Class Class source

  Files folder image Files  /  src  /  Actions  /  City  /  Queries  
File Role Description
  Plain text file IndexQuery.php Class Class source

  Files folder image Files  /  src  /  Actions  /  City  /  Transformers  
File Role Description
  Plain text file IndexTransformer.php Class Class source

  Files folder image Files  /  src  /  Actions  /  Country  
File Role Description
Files folder imageQueries (1 file)
Files folder imageTransformers (1 file)
  Plain text file IndexAction.php Class Class source

  Files folder image Files  /  src  /  Actions  /  Country  /  Queries  
File Role Description
  Plain text file IndexQuery.php Class Class source

  Files folder image Files  /  src  /  Actions  /  Country  /  Transformers  
File Role Description
  Plain text file IndexTransformer.php Class Class source

  Files folder image Files  /  src  /  Actions  /  Currency  
File Role Description
Files folder imageQueries (1 file)
Files folder imageTransformers (1 file)
  Plain text file IndexAction.php Class Class source

  Files folder image Files  /  src  /  Actions  /  Currency  /  Queries  
File Role Description
  Plain text file IndexQuery.php Class Class source

  Files folder image Files  /  src  /  Actions  /  Currency  /  Transformers  
File Role Description
  Plain text file IndexTransformer.php Class Class source

  Files folder image Files  /  src  /  Actions  /  Phone  
File Role Description
  Plain text file FormatAction.php Class Class source
  Plain text file StripAction.php Class Class source
  Plain text file ValidateAction.php Class Class source

  Files folder image Files  /  src  /  Actions  /  State  
File Role Description
Files folder imageQueries (1 file)
Files folder imageTransformers (1 file)
  Plain text file IndexAction.php Class Class source

  Files folder image Files  /  src  /  Actions  /  State  /  Queries  
File Role Description
  Plain text file IndexQuery.php Class Class source

  Files folder image Files  /  src  /  Actions  /  State  /  Transformers  
File Role Description
  Plain text file IndexTransformer.php Class Class source

  Files folder image Files  /  src  /  Actions  /  Timezone  
File Role Description
Files folder imageQueries (1 file)
Files folder imageTransformers (1 file)
  Plain text file IndexAction.php Class Class source

  Files folder image Files  /  src  /  Actions  /  Timezone  /  Queries  
File Role Description
  Plain text file IndexQuery.php Class Class source

  Files folder image Files  /  src  /  Actions  /  Timezone  /  Transformers  
File Role Description
  Plain text file IndexTransformer.php Class Class source

  Files folder image Files  /  src  /  Console  
File Role Description
  Plain text file InitCommand.php Class Class source

  Files folder image Files  /  src  /  Database  
File Role Description
Files folder imageMigrations (5 files)
Files folder imageSeeders (1 file)

  Files folder image Files  /  src  /  Database  /  Migrations  
File Role Description
  Plain text file 2020_07_07_055656_...countries_table.php Class Class source
  Plain text file 2020_07_07_055725_...te_cities_table.php Class Class source
  Plain text file 2020_07_07_055746_...timezones_table.php Class Class source
  Plain text file 2021_10_19_071730_...te_states_table.php Class Class source
  Plain text file 2021_10_23_082414_...urrencies_table.php Class Class source

  Files folder image Files  /  src  /  Database  /  Seeders  
File Role Description
  Plain text file WorldSeeder.php Class Class source

  Files folder image Files  /  src  /  Helpers  
File Role Description
  Accessible without login Plain text file Helpers.php Example Example script

  Files folder image Files  /  src  /  Http  
File Role Description
Files folder imageControllers (1 file, 7 directories)
Files folder imageMiddleware (1 file)
Files folder imageRequests (1 file, 6 directories)

  Files folder image Files  /  src  /  Http  /  Controllers  
File Role Description
Files folder imageCity (1 file)
Files folder imageCountry (1 file)
Files folder imageCurrency (1 file)
Files folder imagePhone (1 file)
Files folder imageState (1 file)
Files folder imageTimezone (1 file)
Files folder imageTraits (1 file)
  Plain text file BaseController.php Class Class source

  Files folder image Files  /  src  /  Http  /  Controllers  /  City  
File Role Description
  Plain text file CityController.php Class Class source

  Files folder image Files  /  src  /  Http  /  Controllers  /  Country  
File Role Description
  Plain text file CountryController.php Class Class source

  Files folder image Files  /  src  /  Http  /  Controllers  /  Currency  
File Role Description
  Plain text file CurrencyController.php Class Class source

  Files folder image Files  /  src  /  Http  /  Controllers  /  Phone  
File Role Description
  Plain text file PhoneController.php Class Class source

  Files folder image Files  /  src  /  Http  /  Controllers  /  State  
File Role Description
  Plain text file StateController.php Class Class source

  Files folder image Files  /  src  /  Http  /  Controllers  /  Timezone  
File Role Description
  Plain text file TimezoneController.php Class Class source

  Files folder image Files  /  src  /  Http  /  Controllers  /  Traits  
File Role Description
  Plain text file ResponseBuilder.php Class Class source

  Files folder image Files  /  src  /  Http  /  Middleware  
File Role Description
  Plain text file Localization.php Class Class source

  Files folder image Files  /  src  /  Http  /  Requests  
File Role Description
Files folder imageCity (1 file)
Files folder imageCountry (1 file)
Files folder imageCurrency (1 file)
Files folder imagePhone (2 files)
Files folder imageState (1 file)
Files folder imageTimezone (1 file)
  Plain text file BaseRequest.php Class Class source

  Files folder image Files  /  src  /  Http  /  Requests  /  City  
File Role Description
  Plain text file IndexRequest.php Class Class source

  Files folder image Files  /  src  /  Http  /  Requests  /  Country  
File Role Description
  Plain text file IndexRequest.php Class Class source

  Files folder image Files  /  src  /  Http  /  Requests  /  Currency  
File Role Description
  Plain text file IndexRequest.php Class Class source

  Files folder image Files  /  src  /  Http  /  Requests  /  Phone  
File Role Description
  Plain text file FormatRequest.php Class Class source
  Plain text file ValidateRequest.php Class Class source

  Files folder image Files  /  src  /  Http  /  Requests  /  State  
File Role Description
  Plain text file IndexRequest.php Class Class source

  Files folder image Files  /  src  /  Http  /  Requests  /  Timezone  
File Role Description
  Plain text file IndexRequest.php Class Class source

  Files folder image Files  /  src  /  Models  
File Role Description
Files folder imageTraits (5 files)
  Plain text file City.php Class Class source
  Plain text file Country.php Class Class source
  Plain text file Currency.php Class Class source
  Plain text file State.php Class Class source
  Plain text file Timezone.php Class Class source

  Files folder image Files  /  src  /  Models  /  Traits  
File Role Description
  Plain text file CityRelations.php Class Class source
  Plain text file CountryRelations.php Class Class source
  Plain text file CurrencyRelations.php Class Class source
  Plain text file StateRelations.php Class Class source
  Plain text file TimezoneRelations.php Class Class source

  Files folder image Files  /  src  /  Routes  
File Role Description
  Accessible without login Plain text file index.php Aux. Auxiliary script

  Files folder image Files  /  tests  
File Role Description
Files folder imageUnit (1 file)
  Plain text file TestCase.php Class Class source

  Files folder image Files  /  tests  /  Unit  
File Role Description
  Plain text file CountryTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:21
This week:2
All time:10,421
This week:115Up
For more information send a message to info at phpclasses dot org.