まず適当にテーブルを作ります。
$ php artisan make:migration create_orders1_table
続いて適当にカラムを作ります。
-> カラム数29
2020_11_26_122330_create_orders1_table.php
public function up() { Schema::create('orders1', function (Blueprint $table) { $table->id(); $table->integer('user_id'); $table->integer('supplier_num'); $table->integer('supplier_id1')->nullable(); $table->integer('supplier_id2')->nullable(); $table->integer('supplier_id3')->nullable(); $table->decimal('supplier_subtotal1', 10, 2)->nullable(); $table->decimal('supplier_subtotal2', 10, 2)->nullable(); $table->decimal('supplier_subtotal3', 10, 2)->nullable(); $table->decimal('total', 10, 2); $table->integer('product_num'); $table->integer('product_id1')->nullable(); $table->integer('product_id2')->nullable(); $table->integer('product_id3')->nullable(); $table->integer('product_id4')->nullable(); $table->integer('product_id5')->nullable(); $table->integer('qty1')->nullable(); $table->integer('qty2')->nullable(); $table->integer('qty3')->nullable(); $table->integer('qty4')->nullable(); $table->integer('qty5')->nullable(); $table->decimal('subtotal1', 10, 2)->nullable(); $table->decimal('subtotal2', 10, 2)->nullable(); $table->decimal('subtotal3', 10, 2)->nullable(); $table->decimal('subtotal4', 10, 2)->nullable(); $table->decimal('subtotal5', 10, 2)->nullable(); $table->text('detail')->nullable(); $table->timestamps(); }); }
適当にmigrateします。
$ php artisan migrate
Migrating: 2020_11_26_122330_create_orders1_table
Migrated: 2020_11_26_122330_create_orders1_table (53.41ms)
mysql> describe orders1;
+——————–+—————–+——+—–+———+—————-+
| Field | Type | Null | Key | Default | Extra |
+——————–+—————–+——+—–+———+—————-+
| id | bigint unsigned | NO | PRI | NULL | auto_increment |
| user_id | int | NO | | NULL | |
| supplier_num | int | NO | | NULL | |
| supplier_id1 | int | YES | | NULL | |
| supplier_id2 | int | YES | | NULL | |
| supplier_id3 | int | YES | | NULL | |
| supplier_subtotal1 | decimal(10,2) | YES | | NULL | |
| supplier_subtotal2 | decimal(10,2) | YES | | NULL | |
| supplier_subtotal3 | decimal(10,2) | YES | | NULL | |
| total | decimal(10,2) | NO | | NULL | |
| product_num | int | NO | | NULL | |
| product_id1 | int | YES | | NULL | |
| product_id2 | int | YES | | NULL | |
| product_id3 | int | YES | | NULL | |
| product_id4 | int | YES | | NULL | |
| product_id5 | int | YES | | NULL | |
| qty1 | int | YES | | NULL | |
| qty2 | int | YES | | NULL | |
| qty3 | int | YES | | NULL | |
| qty4 | int | YES | | NULL | |
| qty5 | int | YES | | NULL | |
| subtotal1 | decimal(10,2) | YES | | NULL | |
| subtotal2 | decimal(10,2) | YES | | NULL | |
| subtotal3 | decimal(10,2) | YES | | NULL | |
| subtotal4 | decimal(10,2) | YES | | NULL | |
| subtotal5 | decimal(10,2) | YES | | NULL | |
| detail | text | YES | | NULL | |
| created_at | timestamp | YES | | NULL | |
| updated_at | timestamp | YES | | NULL | |
+——————–+—————–+——+—–+———+—————-+
29 rows in set (0.00 sec)
続いて、このテーブルにSeederでテストデータを入れたい。