S
S
Sergey Burduzha2022-01-05 12:32:41
Database design
Sergey Burduzha, 2022-01-05 12:32:41

How to store category attributes?

You need to add attributes to the categories: Color, Size.

table for attributes
Schema::create('advert_attributes', function (Blueprint $table) {
            $table->id();
            $table->string('name')->unique();
            $table->string('slug')->unique();
            $table->string('type');
            $table->string('required')->nullable();
            $table->string('variants')->json();
            $table->integer('sort')->default(1);
        });


table for categories
Schema::create('adverts_categories', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name')->index();
            $table->string('slug');
            $table->nestedSet();
        });


I will create an intermediate table for linking categories and attributes using the many_to_many link. Then I will create these connections in the models. And then on the page for creating categories I will get all the attributes, and I will link the necessary ones to this category.
And what to do with attribute options, because each category will have its own? Where to store them?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question