mkojoa's avatar

Best way to create category & product tables ?

Please, I have some issues with my e-commerce database ie category table. I need an efficient way to create something like :

WOMEN [parent] CLOTHING [sub category 1] SPORT GEANS [sub category 2] [list of product here]

please, I need help seriously...

0 likes
7 replies
click's avatar

It looks like a normal parent > child relation what you describe (or tree node).

A category can have one parent category or multiple subcategories. And depending on your requirement a product can be attached to one single category or to multiple categories.

mkojoa's avatar

@martinbean thanks for replying. I have category table with fields[name, ...] and subcategory with fields[category_id, name, product, ..] and product which contains the [ name, category_id ] table.

click's avatar
click
Best Answer
Level 35

@MKOJOA - To be able to create a parent > child > grandchild > etc. relationship you do not need a subcategory table. You could add a nullable parent_id to your category table and setup the relationships.

tree node, please

We are not going to build that for you. This isn't a job site. Google the terms laravel tree or laravel nestedset and you will find some examples

1 like
mkojoa's avatar

@click please you can provide some links because am new to this. please

Please or to participate in this conversation.