Hi!
I want to use simple Paginate to display my query results because I like the minimalistic UI of just to buttons labeled "next" and "previous". My users do not need more than that.
However, I would also like to be able to display the number of total rows matched to the search query. Normally using the pagination ->toal() method would give me that result however it is not available when using simple Paginate as stated in the docs: https://laravel.com/docs/5.7/pagination#paginator-instance-methods
I have tried using count($results) as well but it gives me the length of the paginated query not the length of the query without the pagination.
Any ideas?
Here's some modified code
//Controller
$listings = Listing::where('availability', 'Y')
->orderBy('title', 'asc')
->simplePaginate(100); // results in 1350 results
return view('browse.searchTable', [
'listings' => $listings]);
//View
{{$listings->total()}} //method does not work for simple paginate
{{$listings->count()}} //returns 100
{{count($listings)}} //returns 100
//I want a solution that will return the number 1350 of the original query.
Now that I am writing this question in detail, does this mean I will have to write the same query in my controller to get the row count results and pass it to my view, something like
$count = SELECT COUNT(*) FROM 'listings' WHERE 'availability' = 'y';
//pass to view
Are there any performance drawbacks that come to mind from this approach?
Best,
Biniyam