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

nebulous0's avatar

search query get request from form with pagination

so i have a form that sends a post request to a controller with the search query entered, this returns a paginated list of games that match the query, except since its a post request pagination wont work. so i changed the form to send the query as a get request i changed the route and controller but it only made a 404 not found error and didnt even get to the controller, id like to have additional filtering with this so obviously a get request would be preferred but it just wouldnt work.

the original setup:

the form:

<form method="POST" action="{{ url('/search/games') }}">
				@csrf
				<input type="text" class="form-control" id="fname" name="query" placeholder="Search">
</form>

the route:

Route::controller(GamesController::class)->group(function () {
    Route::post('/search/games',                    'search')->name('search.games');
});

the controller:


    public function search(Request $request)
    {
        dd($request->input('query'));
}

the get setup that returned a 404 error: the form:

<form method="GET" action="{{ url('/search/games') }}">
				<input type="text" class="form-control" id="fname" name="query" placeholder="Search">
			</form>

the route:

Route::controller(GamesController::class)->group(function () {
    Route::get('/search/games/{query}',             'search')->name('search.games');
});

the controller:

    public function search($query)
    {
        dd($query); //it didnt even get here
}

i also tried any:

Route::controller(GamesController::class)->group(function () {
    Route::get('/products/games/{orientation?}',    'games') ->name("games");
    Route::get('/product/games/{product_id}',       'game')  ->name("game");
    Route::any('/search/games/',             'search')->name('search.games');
});
0 likes
1 reply
tykus's avatar
tykus
Best Answer
Level 104

Your URL is /search/games/{query} (which is not correct), but the form action is /search/games (which is correct).

The form data will be appended as a query string; not as URL segment(s), so just change the Route definition:

Route::controller(GamesController::class)->group(function () {
    Route::get('/search/games', 'search')->name('search.games');
});

And in the Controller:

public function search(Request $request)
{
    dd($request->get('query'));
}

Don't forget to append the search query to paginator so links are correct

1 like

Please or to participate in this conversation.