// 親カテゴリー
public function up()
{
Schema::create('product_categories', function (Blueprint $table) {
$table->increments('id')->comment('主キー');
$table->string('category_name')->comment('カテゴリー名');
$table->integer('orderby_id')->comment('表示順序 管理画面で並び替えられる');
$table->timestamps();
$table->softDeletes();
});
// スキーマビルダーではテーブル自体のコメントは出来ない?のでSQL文で実行
DB::statement("ALTER TABLE ".DB::getTablePrefix()."product_categories COMMENT '商品カテゴリ'");
}
// サブカテゴリー
public function up()
{
Schema::create('product_subcategories', function (Blueprint $table) {
$table->increments('id')->comment('主キー');
$table->integer('parent_category_id')->unsigned()->comment('親カテゴリーID 子カテゴリーの場合は親id');
$table->string('subcategory_name')->comment('カテゴリー名 ');
$table->integer('orderby_id')->comment('表示順序 管理画面で並び替えられる');
$table->timestamps();
$table->softDeletes();
// 親カテゴリーIDは、必ずproduct_categoriesに存在する事!
$table->foreign('parent_category_id')->references('id')->on('product_categories');
});
}