Giter VIP home page Giter VIP logo

laraciproid's Introduction

Laraciproid

Laravel City Province ID

Indonesia city and province data migration and seeder for Laravel 5.x.

Installation

Using composer, run this command from your Laravel's project root directory:

composer require matriphe/laraciproid:~1.0

Configuration

Laravel 5.5

Nothing to do. Laraciproid will be loaded automatically.

Laravel 5.1, 5.2, 5.3, and 5.4

Open config/app.php and add this line on autoloaded service providers section.

'providers' => [
	...
	Matriphe\Laraciproid\ServiceProvider::class,
	...
],

Laravel 5.0

Open config/app.php and add this line on autoloaded service providers section.

'providers' => [
        ...
        'Matriphe\Laraciproid\ServiceProvider',
        ...
],

Publish Vendor

php artisan vendor:publish

Or if you want to more specific, and want to force the vendor publishing.

php artisan vendor:publish --provider="Matriphe\Laraciproid\ServiceProvider" --force

This command will add these files to your project:

  • config/laraciproid.php, the configuration file containing tables name.
  • database/migrations/2015_09_28_175100_create_city_province_tables, the migration file.
  • database/sql/city.sql, SQL file for city seed.
  • database/sql/province.sql, SQL file for province seed.
  • database/json/cities.json, JSON file for cities seed.
  • database/json/provinces.json, JSON file for provinces seed.
  • database/seeds/LaraciproidSeeder.php, table seeder file, read the SQL data.
  • app/Models/City.php, city model file.
  • app/Models/Province.php, province model file.

Run Migration

php artisan migrate

Run Database Seeder

php artisan db:seed --class=LaraciproidSeeder

You can add this file to your database/seeds/DatabaseSeeder.php to make it auto loaded on seeding command.

public function run()
{
    Model::unguard();

    $this->call('LaraciproidSeeder');
}

Relationship

Province table has one to many relationship of City table.

// Get all cities under DI Yogyakarta (province_id = 34)
$cities = App\Models\Province::find(34)->cities;

foreach ($cities as $city) {
    // Do something
}

// Get province name of Bogor (city_id = 3271)
$city = App\Models\City::find(3271);
$province_name = $city->province->province_name;

License

The MIT License (MIT). Please see License File for more information.

laraciproid's People

Contributors

matriphe avatar mascang avatar

Watchers

James Cloos 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.