I have a product table:
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->string('title', 100);
$table->integer('price')->index()->nullable();
$table->timestamps();
$table->softDeletes();
});
I have category table:
Schema::create('categories', function (Blueprint $table) {
$table->id();
$table->string('title', 100);
$table->timestamps();
$table->softDeletes();
});
I have a color table:
Schema::create('colors', function (Blueprint $table) {
$table->id();
$table->string('title', 100);
$table->timestamps();
$table->softDeletes();
});
Schema::create('brands', function (Blueprint $table) {
$table->id();
$table->string('title', 100);
$table->timestamps();
$table->softDeletes();
});
All relationships are many-to-many:
Schema::create('category_product', function (Blueprint $table) {
$table->id();
$table->bigInteger('product_id')->unsigned()->index();
$table->foreign('product_id')->references('id')->on('products');
$table->bigInteger('category_id')->unsigned()->index();
$table->foreign('category_id')->references('id')->on('categories');
$table->timestamps();
});
Schema::create('color_product', function (Blueprint $table) {
$table->id();
$table->bigInteger('product_id')->unsigned()->index();
$table->foreign('product_id')->references('id')->on('products');
$table->bigInteger('color_id')->unsigned()->index();
$table->foreign('color_id')->references('id')->on('colors');
$table->timestamps();
});
Schema::create('brand_product', function (Blueprint $table) {
$table->id();
$table->bigInteger('product_id')->unsigned()->index();
$table->foreign('product_id')->references('id')->on('products');
$table->bigInteger('brand_id')->unsigned()->index();
$table->foreign('brand_id')->references('id')->on('brands');
$table->timestamps();
});
How do I get products that have, for example, category = t-shirts, color = green or red and brand = adidas?