Pricing table Many-to- Many relationship
Hi there;
i'm trying to build an "advanced" pricing table like so https://www.chargebee.com/pricing/
to make things little bit more clear, i'm using those tables :
-
plan_groups -
plans -
feature_groups -
features
so the relationships between tables should be like :
-
plan_groups<->plans:one-to-manyrelationship -
plans<->feature_groups:many-to-manyrelationship and here i will need pivot table, let sayplan_pivotwithid,plan_idandfeature_group_idcolumns -
feature_groups<->features:one-to-manyrelationship
until now everything is affordable but the trick is how to make such feature active on a given plan, or display different value according to the plan ?
have a look at this e.g
- Plans :
Go,RiseandScale - Feature group :
Invoicing and Subscription Managementwhich belongs to the 3 plans . - Features :
-
Offline Invoicing: available for all plans -
Calendar Billing: many values depending on the plan -
Advance Invoices: available only for the 3rd plan
-
one solution and i'm not really sure if this is the best approach for this use case :
in table features i added an extra column type (besides id, name, description
)
..
$table->enum('type', ['feature', 'limit'])->default('feature');
..
in the table plan_pivot i added two extra columns feature_id and feature_value
i think to put the logic of insert/update/delete data for the table plan_pivot in an extra controller PlanPivotController
my questions :
- Is there any other good / simple approach ?
- do i need to use custom model (extends
pivotclass) for the intermediate/pivot table ?
Please or to participate in this conversation.