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

Gavmrz's avatar

Best relationship setup for quotes with types

So I have a 'quote' which is prepared by a 'user'. That quote could have one or many 'car rental' quotes + 'insurance quotes' + a couple of other product type quotes. Essentially these are separate quotes that are held together under an overall quote where the customer details are attached to the quote_id and the different information required for insurance/rental is stored in those model tables.


Models:

User (with roles - admin roles prepare a quote and one is the customer role)
Quote
CarRental
CarInsurance

As an end result I would like to be able to output all quotes separately but ordered together. e.g. list all rental/insurance quotes in a table paginated but ordered by quote_id then related model id


rental quote | 		quote_id: 1 | id: 4
rental quote | 		quote_id: 1 | id: 7
insurance quote | 	quote_id: 1 | id: 3
rental quote | 		quote_id: 2 | id: 1
insurance quote | 	quote_id: 2 | id: 2


So far I have come up with a polymorphic relationship with tables: quotes, rentals, insurances and quoteables. And for my query I call Quote::with('type') - type is a hasMany Quoteables relationship. The problem with this setup is that pagination works on the Quote model rather than the individual quotes. So 10 per page will show 10 overall 'quotes' per page but could show 19 individual quotes (rental/insurance) which is confusing

0 likes
0 replies

Please or to participate in this conversation.