1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Illuminate\Support\Facades\Schema; |
4
|
|
|
use Illuminate\Database\Schema\Blueprint; |
5
|
|
|
use Illuminate\Database\Migrations\Migration; |
6
|
|
|
|
7
|
|
|
class CreatePhAddressTables extends Migration |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Run the migrations. |
11
|
|
|
* |
12
|
|
|
* @return void |
13
|
|
|
*/ |
14
|
|
|
public function up() |
15
|
|
|
{ |
16
|
|
View Code Duplication |
Schema::create('regions', function (Blueprint $table) { |
|
|
|
|
17
|
|
|
$table->increments('id'); |
18
|
|
|
$table->string('code', 9)->unique(); |
19
|
|
|
$table->string('name'); |
20
|
|
|
$table->string('region_id', 2)->index(); |
21
|
|
|
}); |
22
|
|
|
|
23
|
|
View Code Duplication |
Schema::create('provinces', function (Blueprint $table) { |
|
|
|
|
24
|
|
|
$table->increments('id'); |
25
|
|
|
$table->string('code', 9)->unique(); |
26
|
|
|
$table->string('name'); |
27
|
|
|
$table->string('region_id', 2)->index(); |
28
|
|
|
$table->string('province_id', 4)->index(); |
29
|
|
|
}); |
30
|
|
|
|
31
|
|
|
Schema::create('cities', function (Blueprint $table) { |
32
|
|
|
$table->increments('id'); |
33
|
|
|
$table->string('code', 9)->unique(); |
34
|
|
|
$table->string('name'); |
35
|
|
|
$table->string('region_id', 2)->index(); |
36
|
|
|
$table->string('province_id', 4)->index(); |
37
|
|
|
$table->string('city_id', 6)->index(); |
38
|
|
|
|
39
|
|
|
$table->index(['province_id', 'region_id'], 'cities_province_regions'); |
40
|
|
|
}); |
41
|
|
|
|
42
|
|
|
Schema::create('barangays', function (Blueprint $table) { |
43
|
|
|
$table->increments('id'); |
44
|
|
|
$table->string('code', 9)->unique(); |
45
|
|
|
$table->string('name'); |
46
|
|
|
$table->string('region_id', 2)->index(); |
47
|
|
|
$table->string('province_id', 4)->index(); |
48
|
|
|
$table->string('city_id', 6)->index(); |
49
|
|
|
|
50
|
|
|
$table->index(['province_id', 'region_id'], 'barangay_idx_1'); |
51
|
|
|
$table->index(['city_id', 'province_id', 'region_id'], 'barangay_idx_2'); |
52
|
|
|
}); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function down() |
56
|
|
|
{ |
57
|
|
|
Schema::drop('barangays'); |
58
|
|
|
Schema::drop('cities'); |
59
|
|
|
Schema::drop('provinces'); |
60
|
|
|
Schema::drop('regions'); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.