ipalaus / geonames

A collection of models and commands to get all the power of GeoNames in Eloquent ORM.
MIT License
64 stars 34 forks source link

Add Laravel 5.1 support #23

Closed JavierMartinz closed 8 years ago

JavierMartinz commented 9 years ago

To be merged as laravel5.1 branch. Tests are not fixed yet.

ipalaus commented 8 years ago

@JavierMartinz could you fix the test when you've a minute?

ken4ward commented 8 years ago

Any guess on how to make this work for Laravel 5.1?

ken4ward commented 8 years ago

Any guess on how to make this work for Laravel 5.1? I'm in need of a tutorial that addresses this? Thanks.

JavierMartinz commented 8 years ago

You only have to use my fork or other compatible fork sent as PR. Anyway, I think @ipalaus is going to merge it as soon the tests are fixed.

ken4ward commented 8 years ago

Kindly help me with the link to your fork

JavierMartinz commented 8 years ago

You only have to add this to your composer.json

    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/JavierMartinz/geonames"
        }
    ],
ken4ward commented 8 years ago

Thanks. After adding this am I to continue with the implementation process of ipalaus/geonames?

ken4ward commented 8 years ago

Could you help me out? I have added your repository, what's next? please I need his urgently. I'm to submit this project at the end of this week and battling with addressing.

ipalaus commented 8 years ago

I'm gonna make this package compatible with 5.1 and 5.2 as today, give me a couple hours.

ipalaus commented 8 years ago

@ken4ward you should be able to required v2.0 for Laravel 5.1 composer require ~2.0 or v3.0 for Laravel 5.2 composer require ~3.0.

ken4ward commented 8 years ago

Thanks. Compliments! I have been able to install it by using "ipalaus/geonames": "dev-master". I don't know if you make changes to the naming convention or namespace, I'm getting this error when I ran php artisan migrate:

[Symfony\Component\Debug\Exception\FatalErrorException]
 Class 'CreateGeonamesNames' not found
ken4ward commented 8 years ago

halfer helped me out. Check it out on this thread: http://stackoverflow.com/questions/34564791/laravel-5-1-geonames-cloning-repository-using-composer/34566361#34566361

ken4ward commented 8 years ago

Thanks. I have been able to migrate. Just to add a Table suffix. Appreciate.

ipalaus commented 8 years ago

@ken4ward thank you, can you point where did you add that suffix so I can push a fix for everyone? Thank you!

ken4ward commented 8 years ago

Sorry for the late reply. I was too busy working on the project because of the timeline, and haven't check back until now. Very sorry.

After publishing thus: php artisan vendor:publish --provider="Ipalaus\Geonames\GeonamesServiceProvider", the migration files were published to my project migration folder. When I ran migration, it throws the error for each migration file. Default migration filename is this: 2013_11_28_170337_create_geonames_names, when this is opened, the naming at the class declaration level is this: CreateGeonamesNamesTable, so the difference is the Table suffix

After previewing the files I saw that the complete naming has a `Table suffix, so I manually deleted them and recreate other migration files. So my migration files looks thus: 2016_01_02_143657_create_geonames_names_table. I just copied and pasted the file content from the default files to the newly created ones.

So, the little effort required is just to rename / recreate the files to have table suffix in the default migration folder: ipalaus/src/migrations/ to have the suffix table.

An example is this: php artisan make: migration create_geonames_names_table on the cmd, and just copy and paste the content into the newly created migration file, before publishing.

invig commented 8 years ago

Further to @ken4ward's point there's also some direct table modification SQL code that's incompatible with Postgres in the migrations - here's the postgres versions:

2014_06_09_204419_geonames_admin_divisions_longer_code_table.php

<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class GeonamesAdminDivisionsLongerCodeTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        DB::statement('ALTER TABLE geonames_admin_divisions ALTER COLUMN code type VARCHAR(32)');
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        DB::statement('ALTER TABLE geonames_admin_divisions ALTER COLUMN code type VARCHAR(6)');
    }
}

2014_06_10_165833_geonames_defaults_and_nullables_table.php

<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class GeonamesDefaultsAndNullablesTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        DB::statement('ALTER TABLE geonames_names ALTER COLUMN elevation SET DEFAULT NULL');
        DB::statement('ALTER TABLE geonames_countries ALTER COLUMN area SET DEFAULT NULL');
        DB::statement('ALTER TABLE geonames_countries ALTER COLUMN phone TYPE VARCHAR(32)');
        DB::statement('ALTER TABLE geonames_countries ALTER COLUMN name_id SET DEFAULT NULL');
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        DB::statement('ALTER TABLE geonames_names ALTER COLUMN elevation SET NOT NULL');
        DB::statement('ALTER TABLE geonames_countries ALTER COLUMN area SET NOT NULL');
        DB::statement('ALTER TABLE geonames_countries ALTER COLUMN phone TYPE VARCHAR(10)');
        DB::statement('ALTER TABLE geonames_countries ALTER COLUMN name_id SET NOT NULL');
    }

}