B
B
Billy Milligan2015-12-06 18:36:29
Laravel
Billy Milligan, 2015-12-06 18:36:29

How to change pagination in Laravel 5.1?

I'm using laravel's standard paging output.
{!! $users->render() !!}
laravel generates the following:

<ul class="pagination">
        <li>
            <a href="http://test.ru/users/?page=1" rel="prev">«</a></li>
            <li><a href="http://test.ru/users/?page=1">1</a></li>
            <li class="active"><span>2</span></li>
            <li class="disabled"><span>»</span>
        </li>
    </ul>

The question is how to make laravel instead of
test.ru/users/?page=1

for the first and previous page displayed in href
test.ru/users

Otherwise it turns out that 2 pages with the same content.
test.ru/users
and
test.ru/users/?page=1

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Tesla, 2015-12-10
@Tesla

It would be correct to make your own Paginator, inherit it from Illuminate\Pagination\Paginatoror Illuminate\Pagination\LengthAwarePaginator, and url()add a check for the first page output in the method. But then you will have to create the paginator manually, passing the necessary parameters to it.
It is strange that in Illuminate\Database\Eloquent\BuilderPaginator it is called directly, and not through DI, this would solve all the problems.

T
tridcatij, 2015-12-10
@tridcatij

If you are too lazy to bother, then the most artisanal way is to register a redirect from test.ru/users/?page=1 to test.ru/users

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question