You could try getting all data in a collection. Check out the groupBy method in the collection object http://laravel.com/docs/5.1/collections#method-groupby
Assuming your collection is called $projectData, your code should be something like this:
$projectData = Project::find($projectID); //this is now a \Illuminate\Database\Eloquent\Collection object which inherits the properties from \Illuminate\Support\Collection
$companyRoles = $projectData->groupBy('company_role'); // you should now have a collection containing other collections of company roles. Each key is the "company_role"
foreach($companyRoles as $role) {
$positions = $role->groupBy('position');
foreach($positions as $position) {
$users = $position->groupBy('name');
}
}
I haven't tested this code, but it should get you started.
Thanks! When I look at these objects it seems really close to what I'm looking for. I'm having trouble figuring out how to put the pieces together actually echo them out in blade though, do I pass all of these variables in to my view and get the collection key in more foreach loops (if so, managed to get the company roles listed but nothing else, lol...)? Could you point me in the right direction?
Edit: it seems like var_dump is revealing that each subsequent foreach is only repeating once... eg.
object(Illuminate\Database\Eloquent\Collection)[247]
protected 'items' =>
array (size=1)
'Schønherr Landskab' =>
object(Illuminate\Database\Eloquent\Collection)[240]
protected 'items' =>
array (size=1)
...
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community