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

jarrodestepp's avatar

Laravel 5.7 Pagination Error - Only First Link Works

I have Laravel 5.7 latest installed and I have run into a problem that I cannot seem to solve. I made this post on StackOverflow: https://stackoverflow.com/questions/53845160/laravel-5-7-latest-pagination-bug-stays-on-1st-page-only-no-matter-what-pagi which has my picture with the JSON response and information on the issue, but to be quick, whenever you click 2 or 3 on the pagination links, the GET updates in the browser, but the data stays the same as page 1 and page 1 in the pagination links is still active no matter what another link you click.

0 likes
47 replies
munazzil's avatar

use instead of this below one in your view.{{ $admins->appends(Request::all())->links() }}

    {!! $admins->links() !!}

else you can use this, because with this '}}' error occured.

    {{!! $admins->appends(Request::all())->links() !!}}
munazzil's avatar

I have updated above check that?

else try with below

{!! $admins->appends(Request::all())->links() !!}
Snapey's avatar

why are you trying to append to the links?

jarrodestepp's avatar

@SNAPEY - Well, i wasn't. That was just where i added that because stackoverflow post made me think that might fix it. I removed it now and made it back to the {{ $admins->links() }}

Snapey's avatar

what happens exactly when you press one of the link buttons?

jarrodestepp's avatar

@SNAPEY - It redirects to the ?page="the one I clicked" but the number 1 is still active and the results stay the same. But the GET in the URL bar is updated. But it's like Eloquent doesn't realize that page 2 is being requested and it thinks 1 is still being requested or something. I ran the form on the laravel welcome. blade view and the pagination worked there without any bootstrap design or anything. You wouldn't think Metronic (Admin Bootstrap Template) would be interfering would you?

jarrodestepp's avatar

So, it worked when i placed the table and the links on the welcome.blade view but when in my metronic view it isn't working. Same with the free theme AdminLTE from the last time i tried it. I just re-installed Laravel on my server and am going to re-build up to where i was at with a clean build.. maybe i touched something that i don't know the wrong way.

munazzil's avatar

Can you use the dd($admins) in your index controller and display the result over here.

public function index()
{
    $admins = Admin::latest()->paginate(1);
    dd($admins);
    return view('admin.settings.admins.index', compact('admins'));
}
munazzil's avatar

Try as like this because when your pagination count is high.

    {{ $admins ->onEachSide(3)->links() }}
jarrodestepp's avatar

@munazzil I have re-installed laravel to see if maybe I did something wrong. I will run this again in a few minutes when i get back to the pagination if it fails again. Thank you for your help!

jlrdw's avatar

@munazzil where are you getting that

Request::all()

thing from, the appends is for an array of query string parameters,

{!! $admins->appends(AN ARRAY GOES HERE)->links() !!}

like:

echo '<td>' . $dogs->appends($myarray)->links() . '</td>';

And myarray is something like:

$myarray = array('psch' => $dogsearch, 'aval' => $aval);

myarray get pass from controller to view.

What is that Request::all() thing.

Please stop slapping it in for a quick reply, Folks will think Request::all() goes in the paginatior instead of the proper parameters.

jarrodestepp's avatar

I am still having the same issue, and I am no longer using appends on my links thing, I only added that because I saw someone post it may help on another site. If anyone would like to see what is going on:

https://fireadwall.com/admin/login username & pass: admin

Go to Settings ->Admins and the bottom portlet is the admin's table and pagination. I will also throw the table to the main site https://fireadwall.com/ and watch the table pagination work there, so could that mean it's my admin template?

jarrodestepp's avatar

I updated the home view https://fireadwall.com to make it the same as the admin settings and pulled the admins query into the default route file (welcome) and the pagination works there. Nothing is different except a different route, same variables and everything. I don't even know what is going on.

realrandyallen's avatar

@JARRODESTEPP - I'm wondering what would happen if you used withPath to specify the proper url

Customizing The Paginator URI - The withPath method allows you to customize the URI used by the paginator when generating links. For example, if you want the paginator to generate links like http://example.com/custom/url?page=N, you should pass custom/url to the withPath method:

Route::get('users', function () {
    $users = App\User::paginate(15);

    $users->withPath('custom/url');

    //
});

https://laravel.com/docs/5.7/pagination#displaying-pagination-results

realrandyallen's avatar

@JARRODESTEPP - Looks like you might have done $admins->withPath('admin/settings/admins'); instead of $admins->withPath('admin/settings_admins');

Can you also dump($admins) at the bottom of your table?

jarrodestepp's avatar

@REALRANDYALLEN - Would anyone like to help me over TeamViewer? None of this is making sense to me and I am unsure where to turn. I did the dump at the end of the table and nothing happened and adding that path only added an extra /admin to a URL that went to 404 not found.

realrandyallen's avatar

@JARRODESTEPP - Note the path in that dump, just 'settings_admins'...it should be the full url. If you also did the dump under the table on your main homepage I bet it's the full url. If you're still using withPath remove that and let's see if the dump changes...also post your routes, or at least the ones that matter for this issue.

realrandyallen's avatar

@JARRODESTEPP - Thanks for the routes, haven't been able to replicate it locally, though I still think it has to do with that path but it's just a hunch, can you also post the code from AdminsController@index

Also, I wanted you to try and remove any withPath not add to it

Snapey's avatar

I've looked at browser behaviour and the web.php you posted and I can only conclude that your unusual prefix and namespace structure is in some way confusing the paginator.

jarrodestepp's avatar

@SNAPEY - Please tell me how to structure it better, I really do want to code the most efficient way and I greatly appreciate you point that out!!

shez1983's avatar

when you hover over the other pagination links, the url that shows up in the bottom of the screen do you see the page=2 or does the page variable always has one?

paginate takes another param

so try giving pageName = 'page' in the paginate function to force it to use page..

can you show the ADMIN model..

realrandyallen's avatar

@SNAPEY - / @jarrod I had the same thoughts, I tested everything except the namespaces locally so it may be that - you may want to go back to basic simple routes and get it working then step by step add in your grouping and prefixes etc testing along the way - if you want to keep them...personally I think it makes the code much harder to decipher

Next

Please or to participate in this conversation.