I am looking for a good way to stay using Eloquent, but to gather data from various models (relations) and output into one collection/array or list. I would like to keep the different data into different models so I can easily reference them and as some of the data in the models can vary per row in the main model.
An example would be team rosters. Assuming I'd have a users table for auth to the site and personal info. I would have a team model. A particular user can be on many different teams. I would have a roster model. A team can have one roster. The roster can have many users. I would have a roles model. A user can have a different role per each team (player, manager, assistant, etc). The user can have a different jersey number per team and some other data like booleans for regestrations, etc.
I've tried pivot tables and I've tried eager loading the relations. I can't seem to find a good way to have many relations loaded from different models at the same time for one or many rows of that roster model.
In my mind I'm thinking the roster model would look something similar to below with foreign key IDs and possibly some columns containing data.
id | team_id | user_id | role_id | league_id | jerseyNum | registered
------------------------------------------------------------------------------------
1 | 3 | 1 | 1 | 2 | 29 | true
2 | 2 | 2 | 1 | 1 | 9 | false
3 | 6 | 3 | 2 | 6 | 68 | false
4 | 9 | 1 | 2 | 3 | 19 | true
In normal SQL terms it feels like a big join statement. I wanted to keep the models as I can reference relations in other parts of the app that don't involve all of this data. If I need to go away from Eloquent, that's fine I was hoping to figure it out as Eloquent makes things simpler.