@@ 7-39 (lines=33) @@ | ||
4 | use Illuminate\Database\Schema\Blueprint; |
|
5 | use Illuminate\Support\Facades\Schema; |
|
6 | ||
7 | class CreateCategoriesTable extends Migration |
|
8 | { |
|
9 | /** |
|
10 | * Run the migrations. |
|
11 | * |
|
12 | * @return void |
|
13 | */ |
|
14 | public function up() |
|
15 | { |
|
16 | Schema::create('categories', function (Blueprint $table) { |
|
17 | $table->increments('id'); |
|
18 | $table->integer('user_id')->unsigned(); |
|
19 | $table->integer('parent_id')->unsigned()->nullable(); |
|
20 | $table->string('name'); |
|
21 | $table->timestamps(); |
|
22 | }); |
|
23 | ||
24 | Schema::table('categories', function (Blueprint $table) { |
|
25 | $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); |
|
26 | $table->foreign('parent_id')->references('id')->on('categories'); |
|
27 | }); |
|
28 | } |
|
29 | ||
30 | /** |
|
31 | * Reverse the migrations. |
|
32 | * |
|
33 | * @return void |
|
34 | */ |
|
35 | public function down() |
|
36 | { |
|
37 | Schema::dropIfExists('categories'); |
|
38 | } |
|
39 | } |
|
40 |
@@ 7-39 (lines=33) @@ | ||
4 | use Illuminate\Database\Schema\Blueprint; |
|
5 | use Illuminate\Support\Facades\Schema; |
|
6 | ||
7 | class CreatePayeesTable extends Migration |
|
8 | { |
|
9 | /** |
|
10 | * Run the migrations. |
|
11 | * |
|
12 | * @return void |
|
13 | */ |
|
14 | public function up() |
|
15 | { |
|
16 | Schema::create('payees', function (Blueprint $table) { |
|
17 | $table->increments('id'); |
|
18 | $table->integer('user_id')->unsigned(); |
|
19 | $table->integer('last_category_id')->unsigned()->nullable(); |
|
20 | $table->string('name'); |
|
21 | $table->timestamps(); |
|
22 | }); |
|
23 | ||
24 | Schema::table('payees', function (Blueprint $table) { |
|
25 | $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); |
|
26 | $table->foreign('last_category_id')->references('id')->on('categories'); |
|
27 | }); |
|
28 | } |
|
29 | ||
30 | /** |
|
31 | * Reverse the migrations. |
|
32 | * |
|
33 | * @return void |
|
34 | */ |
|
35 | public function down() |
|
36 | { |
|
37 | Schema::dropIfExists('payees'); |
|
38 | } |
|
39 | } |
|
40 |