Hemm K
Hemm K

Reputation: 469

Pagination Via Post in Laravel

In a bit of a pickle with dealing with Pagination in Laravel. I have a hefty search query that I'm submitting via GET but the url I produce is over 255 chars (the default limit for URLs).

I would have thought the only logical way I can get around this is to use a Post method instead, but by doing this I remove all help from the Laravel Pagination tool.

The quick and easy win would be to increase my max url length on my server. But no... just no... not doing that thanks.

Can I get a suggestion on the best approach to take here?

Upvotes: 1

Views: 1373

Answers (2)

Suchay
Suchay

Reputation: 29

Yes, Laravel does provide 4 parameters in paginate() method. namely paginate('per_page', ['columns_to_fetch'], 'page', 'current_page').

So, If you want to fetch 5 items per page then you need to enter per_page parameter and then you will use the current_page parameter to fetch the next or any another page.

My case was with Laravel and Vue using Element UI Pagination where i just wanted to post some params via Vue-axios and get the respective paginated data from Laravel.

Upvotes: 3

jedrzej.kurylo
jedrzej.kurylo

Reputation: 40909

Laravel pagination is able to take page value from both GET and POST request so switching to POST shouldn't break the pagination.

Upvotes: 1

Related Questions