dailyadd dailyadd - 1 year ago 91
PHP Question

Count how many projects are in the projects table

I am trying to count how many projects i have in the projects table. So, my code gets the count of project with the specific id.
I simply want to count over all projects that exist in my table.

controller code:

public function countProjects()
$count = Projects::where('id','0')->count();
return view('projects.test')->with('count', $count);

Answer Source

You should be able to just remove the where.

$count = Projects::count();

The where() builder method returns $this after attaching the criteria, in order to allow method chaining. So if you eliminate it, you will still be calling count() on the model.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download