dailyadd dailyadd - 8 months ago 65
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);


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.