Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Robert_B's avatar

onEachSide(2) in pagination not working for me in Laravel 5.8

This is my first post, hello everybody.

Today I have a problem with settings pagination I still get all links :(.

My controller

    $fundations = Fundation::orderBy('id', 'desc')->paginate(1);
    return view('admin.fundation.index', ['fundations' => $fundations]);

My view

{{ $fundations->onEachSide(3)->links() }} <!-- simple version not working to --> 
{!! $fundations->appends(request()->input())->onEachSide(3)->links('vendor.pagination.default') !!}

My result

1 2 >3< 4 5 6 7 8 9 10 11 12

My expected result (but not working)

1 2 >3< 4 5

Please help

0 likes
4 replies
munazzil's avatar

Your using this before the end of your

     {{ $fundations->onEachSide(3)->links() }}

and also check with $fundations = Fundation::orderBy('id', 'desc')->paginate(1); paginate may be >1 check with below.

   $fundations = Fundation::orderBy('id', 'desc')->paginate(2);
Snapey's avatar

it does not really work as you would expect

When you get further on in the sequence - when there are two gaps then either side there will be 2

eg, with 2

1,2 ... 4,5,>7<,8,9 .. 21,22

I can't fathom the logic...

meduz's avatar

My result

1 2 >3< 4 5 6 7 8 9 10 11 12

My expected result (but not working)

1 2 >3< 4 5

I ran into the same situation, and posted my findings in a GitHub answer in Laravel repo, since someone else there had the same question. You’ll find there a workaround and some explanations.

Please or to participate in this conversation.