1. Go to this page and download the library: Download liuyibao/china-district library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
liuyibao / china-district example snippets
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateDistrictTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('district', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->integer('level');
$table->integer('pid');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('district');
}
}
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Liuyibao\ChinaDistrict\Data;
class DistrictTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// 插入时间不超过5秒钟, 可根据实际键名每一条插入,效率会慢一些
foreach(Data::fetchByThousand() as $thousandData){
DB::table('district')->insert($thousandData);
}
}
}
use Liuyibao\ChinaDistrict\Data;
foreach(Data::fetchByThousand() as $thousandDistrict){
// todo
// save database
foreach($thousandDistrict as $district){
echo $district['id'], PHP_EOL; //编号,由1开始,是固定值
echo $district['name'], PHP_EOL; //名称
echo $district['level'], PHP_EOL; //等级: 1省/直辖市, 2市/直辖市区, 3区/县, 4镇/乡
echo $district['pid'], PHP_EOL; //父id
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.