2017 © Pedro Peláez
 

library geonames

A collection of models and commands to get all the power of GeoNames in Eloquent ORM.

image

arberd/geonames

A collection of models and commands to get all the power of GeoNames in Eloquent ORM.

  • Monday, September 5, 2016
  • by ArberD
  • Repository
  • 3 Watchers
  • 2 Stars
  • 721 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 32 Forks
  • 0 Open issues
  • 14 Versions
  • 19 % Grown

The README.md

Eloquent Geonames

Build Status Coverage Status, (*1)

Based on ipalaus/geonames, (*2)

A collection of Eloquent models and Commands to get all the power of GeoNames in Laravel., (*3)

Installation

Add arberd/geonames as a requirement to composer.json:, (*4)

{
    "require": {
        "arberd/geonames": "dev-master"
    }
}

Note: if you're using Laravel 5.1 you can use the version "arberd/geonames": "2.0.*"., (*5)

Update your packages with composer update or install with composer install., (*6)

Once you have installed the dependency, you need to register geonames in Laravel. Open your app/config/app.php and add the next provider to your providers array:, (*7)

'Arberd\Geonames\GeonamesServiceProvider'

If you run now php artisan you should see a new namespace geonames with a few commands related to the package. In order to proceed with the install, run the next command:, (*8)

$ php artisan vendor:publish --provider="Arberd\Geonames\GeonamesServiceProvider"

This will publish the config file to config/geonames.php and the migrations to your database/migrations directory. To be able to control what's going on, we recommend you to manually trigger php artisan migrate., (*9)

Artisan Commands

Import

The import command downloads the needed files (configurable in the config file) and run a seeder for each of them. A few options are provided:, (*10)

  • --country=XX: downloads the specific country (ie. US, ES, FR...)
  • --development: downloads a smaller names file (~10MB) very useful for development environments.
  • --fetch-only: only fetch the files but won't run the seeder. If you want to download the files and then be able to regenerate the tables while offline.
  • --wipe-files: forces a delete of the old files.
$ php artisan geonames:import [--country="..."] [--development] [--fetch-only] [--wipe-files]

Importing a production database can take a while. Main file is ~1GB and the seeder has to insert ~6M rows while creating indexes for some fields. In development environments, I highly recommend to use the --development option and keep complete imports to production. The final table sizes can also affect your local MySQL instance., (*11)

Install

Publish the package's config and run the needed migrations. You can force the config publishing with the --force option., (*12)

$ php artisan geonames:install [-f|--force]

Seed

The is called by the geonames:import command. It extends the Laravel's db:seed but add to extra options: path and country. This is due to the size of the files to import and the queries that we have to run, geonames:import creates a new Symfony\Component\Process\Process for each seeder., (*13)

You shouldn't need to call this command directly., (*14)

Truncate

Do you want to truncate the table and start from scratch? Run:, (*15)

$ php artisan geonames:truncate

Eloquent Models

Continent

  • Relationships:
    • hasMany countries

Country

  • Relationships:
    • belongsTo continent
    • hasMany names

Name

  • Relationships:
    • belongsTo country, eager loaded on every request

... and more to come up!, (*16)

Integrating to a current Eloquent model

Integrating arberd/geonames with your existing Eloquent models as easy as:, (*17)

<?php

class User extends Eloquent {

    public function geoname()
    {
        return $this->belongsTo('Arberd\Geonames\Eloquent\Name');
    }

}

Now you can a geoname_id to your User model and getting the results with a simple:, (*18)

$user = User::with('geoname')->find(1);
echo $user->geoname->name;

The belongsTo country relationship in the Name model is always eager loaded. That means that you can get the country name with the same code as above. You just have to echo:, (*19)

echo $user->geoname->country->name;

You can go a step further and eager loaded the geoname.country.continent relationship (or whatever existing relation in Geoname models):, (*20)

$user = User::with('geoname.country.continent')->find(1);
echo $user->geoname->country->continent->name;

GeoNames

Tables reference

I think the original table names are ugly and they can conflict with other tables in a current project. I switched to a less uglier ones. You can check the migration files to see the used names for our database schema., (*21)

Original Eloquent Geonames
geoname geonames_names
alternatename geonames_alternate_names
countryinfo geonames_countries
iso_languagecodes geonames_language_codes
admin1CodesAscii geonames_admin_divisions
admin2Codes geonames_admin_subdivisions
hierarchy geonames_hierarchy
featureCodes geonames_features
timeZones geonames_timezones
continentCodes geonames_continents

The Versions

05/09 2016

dev-master

9999999-dev

A collection of models and commands to get all the power of GeoNames in Eloquent ORM.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Isern Palaus
by Arber Dervishi

laravel eloquent geonames location

02/01 2016

v3.0.1

3.0.1.0

A collection of models and commands to get all the power of GeoNames in Eloquent ORM.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Isern Palaus

laravel eloquent geonames location

02/01 2016

v3.0

3.0.0.0

A collection of models and commands to get all the power of GeoNames in Eloquent ORM.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Isern Palaus

laravel eloquent geonames location

02/01 2016

v2.0

2.0.0.0

A collection of models and commands to get all the power of GeoNames in Eloquent ORM.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Isern Palaus

laravel eloquent geonames location

17/11 2015

v1.0.2

1.0.2.0

A collection of models and commands to get all the power of GeoNames in Eloquent ORM.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Isern Palaus

laravel eloquent geonames location

11/12 2014

v1.0.1

1.0.1.0

A collection of models and commands to get all the power of GeoNames in Eloquent ORM.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Isern Palaus

laravel eloquent geonames location

28/10 2014

v1.0.0

1.0.0.0

A collection of models and commands to get all the power of GeoNames in Eloquent ORM.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Isern Palaus

laravel eloquent geonames location

11/06 2014

v0.2.5

0.2.5.0

A collection of models and commands to get all the power of GeoNames in Eloquent ORM.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Isern Palaus

laravel eloquent geonames location

10/06 2014

v0.2.4

0.2.4.0

A collection of models and commands to get all the power of GeoNames in Eloquent ORM.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Isern Palaus

laravel eloquent geonames location

09/06 2014

v0.2.3

0.2.3.0

A collection of models and commands to get all the power of GeoNames in Eloquent ORM.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Isern Palaus

laravel eloquent geonames location

14/05 2014

v0.2.2

0.2.2.0

A collection of models and commands to get all the power of GeoNames in Eloquent ORM.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Isern Palaus

laravel eloquent geonames location

09/05 2014

v0.2.1

0.2.1.0

A collection of models and commands to get all the power of GeoNames in Eloquent ORM.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Isern Palaus

laravel eloquent geonames location

09/05 2014

v0.2.0

0.2.0.0

A collection of models and commands to get all the power of GeoNames in Eloquent ORM.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Isern Palaus

laravel eloquent geonames location

03/12 2013

v0.1.0

0.1.0.0

A collection of Eloquent models and Commands to get all the power of GeoNames in Laravel 4.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Isern Palaus

laravel eloquent geonames location