octavianparalescu/judete-orase-comune-sectoare-laravel-seeder

用于行政区域的Seeder(UAT - 'Unități Administrativ-Teritoriale')的 Romania,使用 wikidata

dev-master 2021-07-04 20:11 UTC

This package is auto-updated.

Last update: 2024-09-05 03:24:49 UTC


README

使用 wikidata 的 Romania 行政区域 Seeder

安装

使用 composer 命令:composer require octavianparalescu/judete-orase-comune-sectoare-laravel-seeder:dev-master 由于您可能使用 Seeder 用于开发目的,请使用 --dev 选项将包保存到 require-dev: composer require octavianparalescu/judete-orase-comune-sectoare-laravel-seeder:dev-master --dev

使用

创建一个扩展 UatSeeder 类的 Seeder,定义需要填充的表以及从 WikiData 到您表列的映射

<?php

class CountiesSeeder extends OctavianParalescu\UatSeeder\UatSeeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        $table = 'counties';
        $mapping = [
            'countySirutaId' => 'id',
            'countyLabel' => 'name',
            'typesOfCountiesLabel' => 'type',
        ];
        $insertChunkSize = 200;

        $this->seed($table, $mapping, $insertChunkSize);
    }
}

您也可以在单个 Seeder 中多次使用 seed() 方法(例如,同时填充县和市)

<?php

class CountiesSeeder extends OctavianParalescu\UatSeeder\UatSeeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        $table = 'counties';
        $mapping = [
            'countySirutaId' => 'id',
            'countyLabel' => 'name',
            'typesOfCountiesLabel' => 'type',
        ];

        $this->seed($table, $mapping);

        $table = 'cities';
        $mapping = [
            'countySirutaId' => 'county_id',
            'townLabel' => 'name',
            'typesOfTownsLabel' => 'type',
            'sirutaId' => 'id',
        ];
        $insertChunkSize = 500;

        $this->seed($table, $mapping, $insertChunkSize);

        $this->seed(
            'sate',
            [
                'countySirutaId' => 'county_id',
                'sirutaId' => 'city_id',
                'sateLabel' => 'name',
                'sateCoords' => 'coords',
            ],
            500
        );

    }
}

如您所见,映射是一个数组,键是 Seeder 定义的标志,值是在您的迁移中定义的表列。标志列表如下

countyLabel - string
typesOfCountiesLabel - enum{diviziune administrativă de rangul întâi, județ}
countySirutaId - int
townLabel - string
typesOfTownsLabel - enum{comună, municipiu, oraș, sector al Bucureștiului}
sirutaId - int (town siruta id)
coords - string (format: Point(lat, long))
website - string
sateLabel - string
sateCoords - string (format: Point(lat, long))
sateSirutaId - int (village siruta id)

待办事项

  • 将坐标分割成经纬度