V
V
Vyacheslav Brynzevich2020-02-27 17:29:59
Laravel
Vyacheslav Brynzevich, 2020-02-27 17:29:59

What is the best way to work with multi-table model or replace?

Modifying the question: How to calculate relationships through a relation for a multi-table model in Laravel?

There is a Catalog in which there can be both Brands and Sections
. Brands and Sections can have Products, but in each Catalog, a different number of fields for the Product.

Therefore, now there are 10 tables of different Products for a specific Catalog, so as not to make a table with many unused fields.

Is it possible to organize an Eloquent model in Laravel for such a task, so that later links with the Product table work without pain

? Or is it solved in another way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pLavrenov, 2020-02-27
@SlFomin3

You can leave the main / required number of fields in the table with products (which all products have) and display the rest in meta fields. If you need filtering or search, or something else, you can search by meta fields. And get the relationship right.
Where a catalog can have many Sections and Brands (hasMany Relation)
And products can have many Sections and one (one?) Brand (hasOne Relation).
And depending on the need, you can make a relation to the directory.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question