Retrieving multiple polymorphic entries
Hello everyone,
I'm having a bit of a hard time finding out how to retrieve all of my entries which are polymorphic relationships.
The scenario is the following: I have customers, which can have multiple projects, domains, hostings... ALL of these have a polymorphic relationship with accesses. The reason being that an access can either belong to a general customer or a specific domain. Now I want to display all of these entries, which either belong to the customer directly or one of its realted tables on the view of my customer.
How would I go about this? Of course I can just do
$customer = Customer::with('accesses', 'projects.accesses', 'hostings.accesses');
but that doesn't scale very well if I decide to add other relationships to it later.
My other idea was to simply create an entry for every needed relationship on save of a new access for i.e. a project, so I would attach it to the project and the customer aswell. Would this be too redundant?
All ideas and help are much appreciated! Thank you :)
Please or to participate in this conversation.