Hey, create a new table product_category
Help with Database Design - Products with Multiple Categories
Hey Guys,
I am quite new to building Laravel applications, so please pardon me if this is something very simple.
So I have two tables, namely Products (which contains product data, including categories) and Categories (which contains category title and id).
Now, a product can have multiple categories, what's the best way? Should I store category ids separated by commas in the products table? Should I be creating another table, say Product_Metadata, and have it there? What's the standard way of doing something like this?
Thank You
@alexui you need to add one more table, it's called pivot table, which will link products and categories table
------------------------------------------------
| products table |
------------------------------------------------
| id | title | sales_price | regular_price |
------------------------------------------------
-----------------------
| categories table |
-----------------------
| id | title |
-----------------------
----------------------------------
| product_category table |
----------------------------------
| id | prudct_id | category_id |
----------------------------------
check domentation for many to many relationship https://laravel.com/docs/9.x/eloquent-relationships#many-to-many
Please or to participate in this conversation.