dipesh79/laravel-nepal-address-seeder

Laravel Nepal Address Seeder - 获取尼泊尔省、区和地方级别的迁移和种子。

1.0.0 2024-09-16 10:25 UTC

This package is auto-updated.

Last update: 2024-09-16 10:27:40 UTC


README

Laravel Nepal Address Seeder Package

Laravel Nepal Address Seeder

Latest Stable Version Total Downloads License

此Laravel包允许您添加尼泊尔的省、区和地方级别。

使用/示例

使用Composer安装

composer require dipesh79/laravel-nepal-address-seeder

发布迁移和配置文件供应商文件

php artisan vendor:publish

并发布 Dipesh79\LaravelNepalAddressSeeder\NepalAddressServiceProvider

运行迁移

php artisan migrate

配置文件

在配置目录中的 nepal_address_seeder.php 文件中设置配置。

<?php

return [
    /**
     * Province Model.
     *
     * This is the model that will be used to seed the provinces.
     */
    'province' => '\Dipesh79\LaravelNepalAddressSeeder\src\Models\Province',

    /**
     * Province Name in the database.
     *
     * This is the column name in the database where the province name will be stored.
     */
    'province_name' => 'name',

    /**
     * Opt in if you want to add capital in the database.
     *
     * This will add the capital of the province in the database.
     */
    'add_province_capital' => false,

    /**
     * Province Capital in the database.
     *
     * This is the column name in the database where the province capital will be stored.
     */
    'province_capital' => 'capital',

    /**
     * Opt in if you want to add no of districts in the database.
     *
     * This will add the no of districts in the province in the database.
     */
    'add_province_no_of_districts' => false,

    /**
     * Province No Of District in the database.
     *
     * This is the column name in the database where the province no of districts will be stored.
     */
    'province_no_of_districts' => 'no_of_districts',

    /**
     * District Model.
     *
     * This is the model that will be used to seed the districts.
     */
    'district' => '\Dipesh79\LaravelNepalAddressSeeder\src\Models\District',

    /**
     * District Name in the database.
     *
     * This is the column name in the database where the district name will be stored.
     */
    'district_name' => 'name',

    /**
     * Local Level Model.
     *
     * This is the model that will be used to seed the local levels.
     */
    'local_level' => '\Dipesh79\LaravelNepalAddressSeeder\src\Models\LocalLevel',

    /**
     * Local Level Name in the database.
     *
     * This is the column name in the database where the local level name will be stored.
     */
    'local_level_name' => 'name',

    /**
     * Opt in if you want to add wards in the database.
     * 
     * This will add the wards in the local level in the database.
     */
    'add_local_level_wards' => false,

    /**
     * Local Level Wards in the database.
     * 
     * This is the column name in the database where the local level wards will be stored.
     */
    'local_level_wards' => 'wards',

];

模型

您可以使用自己的模型,或者可以使用我们的包中的模型。

省模型

注意:如果您使用我们的模型,请确保您的迁移中有软删除列。如果您使用我们发布的迁移,那么我们已经有它了。

<?php

namespace Dipesh79\LaravelNepalAddressSeeder\Models;

use bootstrap\LaravelNepalAddressSeeder\src\Models\District;use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class Province extends Model
{
    use SoftDeletes;

    public $timestamps = true;
    
    protected $guarded = [];

    protected $table = 'provinces';

    public function districts(): HasMany
    {
        return $this->hasMany(District::class);
    }
}

区模型

<?php

namespace Dipesh79\LaravelNepalAddressSeeder\Models;

use bootstrap\LaravelNepalAddressSeeder\src\Models\LocalLevel;use bootstrap\LaravelNepalAddressSeeder\src\Models\Province;use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class District extends Model
{
    use SoftDeletes;

    public $timestamps = true;

    protected $guarded = [];

    protected $table = 'districts';

    public function localLevels(): HasMany
    {
        return $this->hasMany(LocalLevel::class);
    }

    public function province(): BelongsTo
    {
        return $this->belongsTo(Province::class, 'province_id');
    }
}

地方级别模型

<?php

namespace Dipesh79\LaravelNepalAddressSeeder\Models;

use bootstrap\LaravelNepalAddressSeeder\src\Models\District;use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;


class LocalLevel extends Model
{
    use SoftDeletes;

    public $timestamps = true;

    protected $guarded = [];

    protected $table = 'local_levels';

    public function district(): BelongsTo
    {
        return $this->belongsTo(District::class, 'district_id');
    }


}

数据库种子

您可以使用以下命令来种子数据库。在种子之前,请确保您的配置文件中正确设置了模型。

php artisan nepal-address:seed

现在您可以在数据库中使用这些数据了。

V 0.0.4 更新

现在您可以在命令中添加一个标志。

仅导入省

php artisan nepal-address:seed --province

仅导入区

php artisan nepal-address:seed --district

仅导入地方级别

php artisan nepal-address:seed --local-level

待办事项

  • 街区数量

许可证

MIT

作者

支持

有关支持,请通过dipeshkhanal79@gmail.com发送电子邮件。