0

I want to create a relationship between parents (which can be Mother or Father models) and their children (Son and Daughter models). For exemple purposes, they are defined like this:

father:
  id
  name

mother:
  id
  name

son:
  id
  name

daughter:
  id
  name

I created a pivot table parent_child:

parent_child:
  parent_id
  child_id
  parent_type
  child_type

How can I create the laravel relations? Most polymorphic relations I can find in the doc only work when one of the two sides of the relation is polymorphic, not both.

1
  • I'm not sure how you'd make this work with the models/tables/relationships you've got defined. For something like this, you'd typically just have a Person model, and you'd define a relationship between each person, with the gender of the Person (usually a column on that table) defining the type (father, son, uncle, nephew, mother, daughter, aunt, niece, etc.). The position of the people would then determine if it's a parent (above), grandparent (above a parent), child (below) grandchild (below parent), etc. Just my 2¢, but I think you have a structure problem, not a problem with polymorph. Commented Mar 24 at 17:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.