我的产品具有更多属性(例如颜色,尺寸,材料),而每个属性都有值(例如颜色具有4个值或材料仅具有1个值),那么产品属性的每个值都有一个价格(例如白色的产品有一个价格,红色的产品有一个价格。
所以我想在Laravel 5.5中设计数据库,对此我感到困惑。
答案 0 :(得分:1)
您需要实施EAV概念
EAV:实体属性值
您需要定义数据库,例如:
products (id, title, description) e.g. t-shirt
entities (id, title) e.g. color, size
values (id, entity_id, value) e.g. yellow, red, medium, large
entityvalues_to_products(id, product_id, entity_id, value_id) e.g. t-shirt have yellow color and could be size of large
还要在entityvalues_to_products
中添加价格属性,并将jquery
添加到onchange尺寸或颜色值,它将比基本产品增加/减少价格。
喜欢
答案 1 :(得分:0)
一种可能的解决方案是使用Pivot Tables将价格存储在产品与属性本身(例如颜色)之间的枢轴/关系上