Relation Manager for pivot table

Hi everyone! Could do with some guidance please. I have the following models: 1. Sites 2. Services 3. Contractors I have a pivot table called site_services_contractors that has the following: site_id, service_id, contractor_id The idea being that for a specific site we can record which contractor carries out a particular service. I'm trying to set this up as a relation manager in Filament but I can't seem to get it working. Has anyone done anything similar to this before?
4 Replies
Brian Kidd
Brian Kidd4mo ago
@John Trickett If a service belongs to a site, you should only have service and contractor in the pivot table. Does a relationship exist between site and service?
John Trickett
John TrickettOP4mo ago
Hi @Brian Kidd. Services can have multiple sites, so the site_id is defined in the pivot. I'm beginning to think the solution maybe to treat this three way pivot as a model, then create a relation manager for that and specify the relationship between the pivot model and site, then use the relationship from the pivot model to services and contractors for the remaining data.
Brian Kidd
Brian Kidd4mo ago
I agree, complex models like this sometimes require doing this. In my opinion, you’re on the right track with that thinking
John Trickett
John TrickettOP4mo ago
Thanks Brian. I think I just needed to step away from the code and have a cup of tea to think! I think that will work, I will let you know!
Want results from more Discord servers?
Add your server