Support the ongoing development of Laravel.io →
Database Eloquent Blade
Last updated 1 year ago.
0

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.

Last updated 8 years ago.
0

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)
              ...
Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

nchan0154 nchan0154 Joined 8 Oct 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.