Laravel Count from database -


i want count amount of workers company has. shows like: mcdonalds - 200 employees (example)

model:

 public function gettotalworkers()     {         return $this->hasmany('app\user')->wherecompanyid($this->company_id)->count();      } 

view:

@foreach($companies $company) <tr>     <td>{!! link_to_route('company.edit', $company->name, [$company->id] )!!}</td>     <td>{{ $gettotalworkers }}</td>     <td>{{ ' /' }}</td>     <td>{{ $company->parent_id }}</td>     <td>{{ ' /' }}</td>     <td>{{ $company->active }}</td> </tr> @endforeach 

controller:

public function index() {     $gettotalworkers = $this->company->gettotalworkers();     $companies = company::get();      return view('company.index', ['companies' => $companies, 'gettotalworkers' => $gettotalworkers]); 

but gives me error: call member function gettotalworkers() on non-object how can fix or doing wrong?

it looks calling gettotalworkers() on $post, not $company on fourth line of view snippet have posted.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -