01.
<?php
02.
03.
use
Illuminate\Database\Schema\Blueprint;
04.
use
Illuminate\Database\Migrations\Migration;
05.
06.
class
CreateDistrictsTable
extends
Migration
07.
{
08.
09.
10.
11.
12.
13.
public
function
up()
14.
{
15.
Schema::create(
'districts'
,
function
(Blueprint
$table
) {
16.
$table
->increments(
'id'
);
17.
$table
->string(
'name'
);
18.
$table
->timestamps();
19.
});
20.
21.
Schema::table(
'districts'
,
function
(Blueprint
$table
) {
22.
$table
->integer(
'province_id'
)->unsigned()->after(
'name'
);
23.
$table
->foreign(
'province_id'
)->references(
'id'
)
24.
->on(
'provinces'
)->onDelete(
'cascade'
);
25.
});
26.
}
27.
28.
29.
30.
31.
32.
33.
public
function
down()
34.
{
35.
Schema::table(
'districts'
,
function
(Blueprint
$table
) {
36.
$table
->dropForeign(
'districts_province_id_foreign'
);
37.
});
38.
39.
Schema::drop(
'districts'
);
40.
}
41.
}