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

khanimranm's avatar

What is the right approach in handling various combination of relationship.

Fees can be charged in one out of eight ways in my case as in below relationships

1. group->location->service->provider->fee

2. group->service->provider->fee

3. group->location->provider->fee

4. group->location->service->fee

5. group->provider->fee

6. group->service->fee

7. group->location->fee

8. group->fee

Example - A group has 3 Locations, 5 Services, 10 Providers

Case 1: 150 Records (1 * 3 * 5 * 10) group->location->service->provider->fee
Case 2: 50 Records (1 * 5 * 10) group->service->provider->fee
Case 3: 30 Records (1 * 3 * 10) group->location->provider->fee
Case 4: 15 Records (1 * 3 * 5) group->location->service->fee
Case 5: 10 Records (1 * 10) group->provider->fee
Case 6: 5 Records (1 * 5) group->service->fee
Case 7: 3 Records (1 * 3) group->location->fee
Case 8: 1 Record (1) group->fee

Please suggest right approach, tables, eloquent relationship to handle this.

0 likes
5 replies
khanimranm's avatar

Please suggest the pivot table structure in polymorphic relation

shez1983's avatar

seriously? the docs tell you how to structure your table....

1 like
khanimranm's avatar

Thank you for the help both of you.

I read the document earlier too, but was not easy for me to understand as I am new to framework and laravel is my first.

I was confused with what eloquent models to develop to take care of my needs and how to transform it into polymorphic relation.

I think, I have the answers now. Good to have the laravel community at help.

Please or to participate in this conversation.