I'm using Laravel 5.2 and LengthAwarePaginator to paginate my Collection, everything goes well except the lastPage() method, it gives me 1 as always.
Here is my code:
I build the collection by using foreach loop:
$collection = collect();
foreach ($rows as $row) {
$collection->push($row);
}
then I paginate it using:
$collection = $collection->sortBy('id')->forPage($page, $page_limit);
$collection = new LengthAwarePaginator($collection, $collection->count(), $page_limit, $page);
return $collection;
Here is my pagination information:
- ->currentPage(): 3 (I am on page 3 right now)
- $per_page_limit: 8
- Total item in Collection: 77
- ->lastPage(): 1 (this is the problem)
My question is why ->lastPage() value is always 1 ?
Any help will be very helpful for me.
Thanks in advance