Loach's avatar
Level 11

Help me understand how paginated search works.

I have a form that I am using to search. I post to a new page that shows the search results, however when i click on the 2nd pagination link i get an error.

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message

Here is the form.

<form method="POST" action="/searchresults" class="form-horizontal">
{{ csrf_field() }}
Fields
</form>

Here is the routes

Route::get('/search', 'UserController@searchView')->name('search.view');

Route::post('/searchresults', 'UserController@search');
How can I make a paginated search work?


0 likes
2 replies
Snapey's avatar
Snapey
Best Answer
Level 122

You need to change it into a GET request rather than a post, and make sure you append the search term to the subsequent pages

bluemagenta's avatar

the pagination link use GET method to the current url (/searchresults). so I recommend to change the Route to use get:

Route::get('/searchresults', 'UserController@search')->name('search');

of course you also need to change the form method:

<form method="GET" action="/searchresults" class="form-horizontal">

Please or to participate in this conversation.