2

I'm new to laravel. I have a table named as projects and, I need to count number of all rows of the projects table. I have tried using id column to count all the rows like the following function

public function totalprojects() { $projects = Project::where('id')->count(); return view('summarys.summary')->withProjects($projects); } 

but its returning 0 how can I manage this?

1 Answer 1

9

in your controller

(1) using Eloquent :

 use App\Project; public function totalprojects() { $total_projects = Project::count(); return view('summarys.summary')->with(['total'=>$total_projects]); } 

(2) using Query Builder :

 use DB; public function totalprojects() { $total_projects = DB::table('projects')->count(); return view('summarys.summary')->with(['total'=>$total_projects]); } 

in your blade :

<p>{{ $total }}</p> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.