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

harit's avatar
Level 1

How to send parameters in paginate function

Hi, In one of the online project I have seen we can pass arguments in laravel paginator by this way. $aData->paginate($aRequest['rowCount'], ['*'], 'page', $aRequest['current']) //where $Data is an eloquent query object But I didn't see any documentation regarding this. I checked the official documentation also, but not seeing such an implementation. Basically I need data table pagination (with out other plugins). So I need to get the total record count also. So by using paginate function I think I can implement in an effective way. Can anybody have any suggestion regarding this.

Thanks,

0 likes
4 replies
Snapey's avatar

Can you explain more what you mean?

Suppose $users is a paginated eloquent collection

$users = User::paginate(10);

You can append attributes to the pagination links;

{{ $users->appends(['sort' => 'votes'])->links() }}

This would result in a url like /users?page=2&sort=votes

You can get the total record count with $users->total()

2 likes
jlrdw's avatar

Are you using Length aware paginator. Plus if using pretty url you have to handle this custom.

By pretty url I mean using route parameters instead of a query string. From what I have seen most use:

spatie/laravel-paginateroute

If maintaining pretty url.

In the case of query string, you can build it in the controller, as example:

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

Pass that to view, and in the view:

{{ $dogs->appends($params)->links() }}

But there's a whole API to learn more about Length aware paginator, or regular paginator, etc.

But the appends on the paginator generates query string, not "pretty url"

A custom paginator isn't hard to write, just some basic math skills.

Wonderful, noticed this is another old post.

Please or to participate in this conversation.