Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cizario's avatar

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-many relationship

  • plans <->feature_groups : many-to-many relationship and here i will need pivot table, let say plan_pivot with id, plan_id and feature_group_id columns

  • feature_groups <-> features : one-to-many relationship

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, Rise and Scale
  • Feature group : Invoicing and Subscription Management which 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 pivot class) for the intermediate/pivot table ?
0 likes
0 replies

Please or to participate in this conversation.