Skip to content

Commit

Permalink
Merge pull request #33 from djunehor/fetch-cities-by-country
Browse files Browse the repository at this point in the history
Truncate tables before seeding for consistent IDs
  • Loading branch information
ichtrojan authored Jan 10, 2020
2 parents a44d3ea + d1ac282 commit fb11d8b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/database/seeds/CitiesTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class CitiesTableSeeder extends Seeder
{
Expand All @@ -14,6 +15,10 @@ class CitiesTableSeeder extends Seeder
public function run()
{
$citiesTable = config('location.cities_table', 'cities');

Schema::disableForeignKeyConstraints();
DB::table($citiesTable)->truncate();
Schema::enableForeignKeyConstraints();

$cities = array(
array('name' => "Bombuflat",'state_id' => 1),
Expand Down
5 changes: 5 additions & 0 deletions src/database/seeds/CountriesTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class CountriesTableSeeder extends Seeder
{
Expand Down Expand Up @@ -263,6 +264,10 @@ public function run()
array('id' => 246,'code' => 'ZW','name' => "Zimbabwe",'phonecode' => 263),
);

// Fix for issue #29 https://github.com/ichtrojan/laravel-location/issues/29
Schema::disableForeignKeyConstraints();
DB::table($countriesTable)->truncate();
Schema::enableForeignKeyConstraints();
DB::table($countriesTable)->insert($countries);
}
}
5 changes: 4 additions & 1 deletion src/database/seeds/StatesTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class StatesTableSeeder extends Seeder
{
Expand Down Expand Up @@ -4138,7 +4139,9 @@ public function run()
array('name' => "Matabeleland South",'country_id' => 246),
array('name' => "Midlands",'country_id' => 246)
);

Schema::disableForeignKeyConstraints();
DB::table($statesTable)->truncate();
Schema::enableForeignKeyConstraints();
DB::table($statesTable)->insert($states);
}
}

0 comments on commit fb11d8b

Please sign in to comment.