Git Product home page Git Product logo

laravel-nepal-address-seeder's Introduction

Laravel Nepal Address Seeder Package

Laravel Nepal Address Seeder

Latest Stable Version Total Downloads License

This Laravel package allows you to add Province, District and Local Levels of Nepal.

Usage/Examples

Install Using Composer

composer require dipesh79/laravel-nepal-address-seeder

Publish Vendor File For Migration And Configuration File

php artisan vendor:publish

And publish Dipesh79\LaravelNepalAddressSeeder\NepalAddressServiceProvider

Run Migration

php artisan migrate

Config File

Set the configuration in the nepal_address_seeder.php file in the config directory.

<?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',

];

Model

You can use your own model, or you can model from our package.

Province Model

NOTE: If you are using our model, make sure you have soft delete column in your migration. If you are using our published migration, then we already have it.

<?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);
    }
}

District Model

<?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');
    }
}

Local Level Model

<?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');
    }


}

Database Seeding

You can seed the database using the following command. Before seeding, make sure you have the correct model in your configuration file.

php artisan nepal-address:seed

Now you can use the data in your database.

V 0.0.4 Update

Now you can add a flag to the command.

Import Province Only

php artisan nepal-address:seed --province

Import District Only

php artisan nepal-address:seed --district

Import Local Level Only

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

TODOS

  • Wards Count

License

MIT

Author

Support

For support, email [email protected].

laravel-nepal-address-seeder's People

Contributors

dipesh79 avatar

Stargazers

Achyut Neupane avatar

Watchers

 avatar

Forkers

achyutkneupane

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.