V
V
Vladislav2015-10-28 11:17:00
Laravel
Vladislav, 2015-10-28 11:17:00

How to make pagination without query string in laravel 5.1 using LengthAwarePaginator?

I want to make pagination, but without the ugly ?page=. I'm trying to use the LengthAwarePaginator class for this. Passing parameters to the constructor

$paginator = LengthAwarePaginator($authors, count($authors), 10, $page);

Where:
$authors is a collection of entries received from the model.
count($authors) - total number of entries
10 - how many to display per page
$page - current page I get from query string, for example example.ru/some_text/2 <- is the page number.
I get a $paginator object of type LengthAwarePaginator, go to example.ru/some_text/2 and want to get the current page, which is equal to 2, but in the end I get 1. I.e. Laravel still wants me to access ?page=2. So what's the point of LengthAwarePaginator? And how can this be done? Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2015-10-28
@MrBikus

I end up with 1
What do you mean by this?
$authors is already a truncated collection?
The first argument to LengthAwarePaginator is the collection of the current page, and the second argument is the total number of elements on all pages. You are transmitting the same thing.

A
Alexander Fanamurov, 2016-01-29
@Fanamura

Can be used: https://packagist.org/packages/spatie/laravel-pagi...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question