Coder Social home page Coder Social logo

nminhduc / vietnam-maps Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hoangphidev/vietnam-maps

0.0 0.0 0.0 322 KB

🚀 Laravel database of Vietnam's area.

Home Page: https://packagist.org/packages/hoangphi/vietnam-maps

License: MIT License

PHP 100.00%

vietnam-maps's Introduction

Vietnam Maps

Database of Vietnam's area.

Data are taken directly from the General Statistics Office of Vietnam.

Latest Version on Packagist Total Downloads

Install

composer require hoangphi/vietnam-maps

Extracting

Method 1:

Extract directly via command:

php artisan vietnam-map:install

Method 2:

Copy file config và migration

php artisan vendor:publish --provider="HoangPhi\VietnamMap\VietnamMapServiceProvider"

Customize config và migration

  1. Rename table

Open file config/vietnam-maps.php and config:

'tables' => [
    'provinces' => 'provinces',
    'districts' => 'districts',
    'wards'     => 'wards',
],
  1. Rename column

Open file config/vietnam-maps.php and config:

'columns' => [
    'name'        => 'name',
    'gso_id'      => 'gso_id',
    'province_id' => 'province_id',
    'district_id' => 'district_id',
],
  1. Add column

Open the following migration files and customize if you need:

database/migrations/{datetime}_create_vietnam_maps_table.php

Run migration

php artisan migrate

Download và import into database

php artisan vietnam-map:download

Usage with Models

  1. Get all provinces, districts, wards
    use HoangPhi\VietnamMap\Models\Province;
    use HoangPhi\VietnamMap\Models\District;
    use HoangPhi\VietnamMap\Models\Ward;

   class DevController extends Controller
   {
       ...
       public function dev()
       {
           $provinces = Province::all();
           $districts = District::all();
           $wards = Ward::all();
           ...
       }
   }
  1. Get data using relationship
    use HoangPhi\VietnamMap\Models\Province;

   class DevController extends Controller
   {
       ...
       public function dev()
       {
           $province = Province::first();
           $districts = $province->districts;
           ...
       }
   }
  1. Relation in Province.php
    class Province extends Model
    {
        ...
        public function districts()
        {
            return $this->hasMany(District::class);
        }
    }
  1. Relation in District.php
    class District extends Model
    {
        ...
        public function province()
        {
            return $this->belongsTo(Province::class, config('vietnam-maps.columns.province_id'), 'id');
        }
        
        public function wards()
        {
            return $this->hasMany(Ward::class);
        }
    }
  1. Relation in Ward.php
    class Ward extends Model
    {
        ...
        public function district()
        {
            return $this->belongsTo(District::class, config('vietnam-maps.columns.district_id'), 'id');
        }
    }

Changelog

Please see CHANGELOG for more information what has changed recently.

Security

If you discover any security-related issues, please email [email protected] instead of using the issue tracker.

Credits

References

  1. General Statistics Office of Vietnam
  2. Vietnam Zone

License

The Laravel framework is open-sourced software licensed under the MIT license.

vietnam-maps's People

Contributors

hoangphidev avatar

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.