agoalofalife / 地理信息
v0.5.0
2021-02-05 11:44 UTC
Requires
- php: >=7.2
- illuminate/config: ^8.0
- illuminate/database: ^8.0
- illuminate/support: ^8.0
- symfony/console: ^5.0
Requires (Dev)
- mockery/mockery: ^0.9.9
- phpunit/phpunit: ^6.1
README
地区地理信息
这是什么?
此包解决了数据库中国家、地区、定居点层次结构的问题。只需在控制台运行几个命令,就可以部署所有必要的国家,无论国家还是语言。
包的安装
为了安装,您必须从 composer 运行命令
composer require agoalofalife/geography
数据迁移
运行以下命令
vendor/bin/geography install
按照指示逐步进行,继续输入信息。
- 数据库选择
======================================
Please choose your database type :
[ 0 ] mysql
[ 1 ] postgres
- 选择你的主机
Enter host for database , please : localhost
- 数据库名称
Enter database name, please : test
- 数据库用户
Enter database username, please : root
- 数据库密码(未显示)
Enter database password, please :
- 选择语言
Please select your native language :
[0] ru
[1] en
[2] ua
[3] be
[4] es
[5] fi
[6] de
[7] it
>
- 选择您想要迁移的国家,例如我需要几个国家(澳大利亚和巴西),分别,我需要输入:AU,BR
the list of countries you can see here 3166-1 alpha-2
you can specify multiple countries separated by commas
example EN, RU
Enter the country you wish to migrate, please :
经过一段时间后,根据信息量的大小,您将在我的数据库中看到三个表
- 国家
- 地区
- 城市
You have just selected: AU,BR
3/3 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
恭喜所有成功者!
Laravel 集成
由于 Laravel 使用 Seeder 和 Migration 作为其环境中的表,我们可以自由地将它复制到您的 Laravel 项目中!
vendor/bin/geography migrate:laravel
之后,您可以在数据库和配置文件夹中获得您的文件。
要配置您想要迁移的语言和国家,您必须更改 config/geography.php 配置文件
return [
// Your native language
// 0 — Russian,
// 1 — Ukrainian,
// 2 — Belarusian,
// 3 — English,
// 4 — Spanish,
// 5 — Finnish,
// 6 — German,
// 7 — Italian.
'locale' => 0,
// Country you wish to migrate
// standard 3166-1 alpha-2
// example RU,AU
'country' => 'RU',
'nameTable' => [
'country' => 'country',
'regions' => 'regions',
'cities' => 'cities'
],
'access_token' => ''
];
接下来,您需要执行
composer dump
php artisan migrate
php artisan db:seed
или для seeder :
php artisan db:seed --class=CountryTableSeeder
php artisan db:seed --class=RegionsTableSeeder
php artisan db:seed --class=CitiesTableSeeder
之后,您可以轻松地移除包,不必担心!