Get total pagination results

I would like to get the total number of users on the page where all users are listed. This page should be paginated.

So far this is what I came up with:

controller

$users = User::paginate(10);
return View::make('index', compact('users'));

View:

{{{ count($users) }}}

But this only gives me the number of users for the current page. I would like to calculate a complete set of results, if possible, without querying another database time.

+9
source share
2 answers

In Laravel 4 use:

{{ $users->getTotal() }}

Docs


In Laravel 5 use:

{{ $users->total() }}

Docs

+35
source

controller

$products = ProductMaster::paginate(10); //1 page with 10 products

return view('index',compact('products'));

Look

 {{ $products->total() }}   //show total products in your database
+3
source

All Articles