Hello,
I'm creating a small website for myself to show some digital products.
Each product belongs to a category, and a category has many products.
Every category has specific attributes.
For example, a HTML website may be retina ready, responsive…
A WordPress website may be retina and responsive too, but also support some plugins.
I have created a migration, but I'm not sure it is best optimized, so I would like to get your opinion and advices.
I am sure it would help other people, because it is very common to create attributes for a eCommerce, portfolio or anything else.
Schema::create('attributes', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->integer('attribute_type_id')->unsigned()->index();
$table->string('photo')->nullable();
$table->boolean('visible')->default(true);
$table->integer('position')->unsigned()->default(1);
});
Schema::create('attribute_type', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->boolean('visible')->default(true);
$table->integer('position')->unsigned()->default(1);
});
Schema::create('attribute_category', function (Blueprint $table) {
$table->integer('attribute_id')->unsigned()->index();
$table->foreign('attribute_id')->references('id')->on('attributes')->onDelete('cascade');
$table->integer('category_id')->unsigned()->index();
$table->foreign('category_id')->references('id')->on('attributes')->onDelete('cascade');
});