Usual's avatar

Use pagination in POST request.

I am coding a contact search system by laravel, and use pagination to pagine search results.So when I post a form to url like "search/contact", the system works and display right results and right pagination links in page.But then, when I click the page links with a url like "search/contact/?page=7", a GET request is sent by browser, consequently I lose my search data in this request.

So, how can I fix it?thx.

0 likes
10 replies
Usual's avatar

@jlrdw yeah, pagination links is just an a tag that can only send a GET request.Does Laravel provide some other mechanisms to pagine results set?

jlrdw's avatar

If you want to post using pagination you would have to use something like a session variable to store which page you are on and pass that each time. But passing that in the query string is standard practice even large sites like FedEx do it that way. You should study some basic crud examples.

Usual's avatar

@jlrdw I think maybe I can use GET request instead of POST request to achieve query function, and then use $object->appends(Input::query())->render() to pass that in pagination links.

ayekoto's avatar

@Usual did you ever got this issue resolved, if Yes, How?

facing the same challenge right away.

Trying to use POST request from a Form input to display result on a page and then paginate those results cos they pretty long

ayekoto's avatar

@jlrdw , can use pls expantiate more on

If you want to post using pagination you would have to use something like a session variable to store which page you are on and pass that each time. But passing that in the query string is standard practice even large sites like FedEx do it that way. You should study some basic crud examples.

jlrdw's avatar

Look at this very forum you are on, now when I edit or add a thread, look at the button, it says post your reply. So that is a post. Now when you are paging through the threads those would be get request. Likewise when you click on a thread it opens for viewing or editing. Normally in a table you would have a edit button but here you simply click on the thread.
Same difference normally the edit button or link is sent with get request. But after a successful update it is normally a POST request.

jekinney's avatar

Something like this you send your post request to method in controller. Handle the request and pass the data to a different controller method to display the results paginates the will handle subsequent get requests.

MDRaselRana's avatar

At first in your route set resource method, then you can pass your key in your blade page thorough controller. Then in your controller you can use append method in your pagination link. Below i am giving you some example: Route::resource( '/search', 'BillingController@find' ); Controller: ->with( 'region', $region ) // key for you search

Blade: $regionList->appends(['region' => $region ])->render()

Please or to participate in this conversation.