PHPackages                             arberd/geonames - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. arberd/geonames

ActiveLibrary[Database &amp; ORM](/categories/database)

arberd/geonames
===============

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

v3.0.1(10y ago)12.1k1MITPHPPHP &gt;=5.5.9

Since Dec 3Pushed 9y ago3 watchersCompare

[ Source](https://github.com/ArberD/geonames)[ Packagist](https://packagist.org/packages/arberd/geonames)[ RSS](/packages/arberd-geonames/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (8)Versions (14)Used By (0)

Eloquent Geonames
=================

[](#eloquent-geonames)

[![Build Status](https://camo.githubusercontent.com/78f598c1c5f89cb22fbc6a89a974962d646609f129909ab2236de91a0d2ca49e/68747470733a2f2f7472617669732d63692e6f72672f6172626572642f67656f6e616d65732e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/arberd/geonames)[![Coverage Status](https://camo.githubusercontent.com/8dbbb0f6d0c8d6da2a30807c26da5d241be5f8d2c574a51ce1cccc96329f6a19/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6172626572642f67656f6e616d65732f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/arberd/geonames?branch=master)

Based on ipalaus/geonames

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

Installation
------------

[](#installation)

Add `arberd/geonames` as a requirement to composer.json:

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

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

Update your packages with `composer update` or install with `composer install`.

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:

```
'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:

```
$ 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`.

Artisan Commands
----------------

[](#artisan-commands)

### Import

[](#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:

- `--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.

### Install

[](#install)

Publish the package's config and run the needed migrations. You can force the config publishing with the `--force` option.

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

### Seed

[](#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.

You shouldn't need to call this command directly.

### Truncate

[](#truncate)

Do you want to truncate the table and start from scratch? Run:

```
$ php artisan geonames:truncate
```

Eloquent Models
---------------

[](#eloquent-models)

### Continent

[](#continent)

- Relationships:
- hasMany `countries`

### Country

[](#country)

- Relationships:
- belongsTo `continent`
- hasMany `names`

### Name

[](#name)

- Relationships:
- belongsTo `country`, eager loaded on every request

... and more to come up!

Integrating to a current Eloquent model
---------------------------------------

[](#integrating-to-a-current-eloquent-model)

Integrating `arberd/geonames` with your existing Eloquent models as easy as:

```
