Home > Enterprise >  Laravel: complex Many to Many Polymorphic Relationship for conditions and actions
Laravel: complex Many to Many Polymorphic Relationship for conditions and actions

Time:07-09

The Method model is a container of conditions (triggers) and actions.

  • A Method has multiple Condition
  • Each Condition has multiple Action

We can have different types of Condition, for instance:

  • Order amount between 0 and 500 USD
  • Order weight between 10 and 100 pounds

And we can have different types of Action, for instance:


enter image description here

We are creating a table for each type of condition and a table for each type of action. That way we don't end up with a table full of columns to encompass each possible scenario.

The problem is: how to create this Polymorphic Relationship?


Starting with Conditions

My database looks like:

  • Related