📦 world/ nnjeim
A Laravel package which provides a list of the countries, states, cities, currencies, timezones, languages and IP Geolocation.
Открыть на GitHub ↗обновлён 1нед назад
Звёзды
★ 983
Форки
143
За неделю
—
За месяц
—
Рост %
—
Язык
PHP
Установка и запуск
Installation
First, set your application environment to local:
set APP_ENV=local
Then, install the package via composer:
composer require nnjeim/world
Optionally, set the WORLD_DB_CONNECTION environment variable to your desired database connection.
Automated Installation
Run the following Artisan command to automate the installation process:
php artisan world:install
Manual Installation
If you prefer to install the package manually, follow these steps:
- Publish the package configuration file:
php artisan vendor:publish --tag=world --force
- Run the migrations:
php artisan migrate
- Seed the database:
php artisan db:seed --class=WorldSeeder
Usage
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
List all the cities by country id
use Nnjeim\World\WorldHelper;
new class {
protected $world;
public function __construct(WorldHelper $world) {
$this->world = $world;
}
$action = $this->world->cities([
'filters' => [
'country_id' => 182,
],
]);
if ($action->success) {
$cities = $action->data;
}
}
Use the API cities endpoint:
…
Из README репозитория · полный README на GitHub
Категории
Теги
citiescountriescountries-apicountrycurrenciesgeoipgeolocationgeolocation-apilanguagelanguageslaravellaravel-packagestatestimezones