Thursday, March 9, 2017

Laravel - Getting count from many-to-many table

So I want to get a count of all the projects in different stages for an employee ($id). So something like:

Queued - 3 In Progress - 7 Launched - 5

I have a projects table and an employees table and an employee_project table.

How can I get the stages for the projects for a particular employee? This does not work as it lists out every status and just 1 next to it:

@foreach ($employee->projects as $project)
   <h3></h3>
   <h3></h3>
@endforeach

Any ideas how to do this?



via robk27

Advertisement