Answer the question
In order to leave comments, you need to log in
How to compose routes in Laravel 5 for get form?
Hello, please tell me, there is a search form:
<form action="/search" method="get">
<input name="q" type="text" class="text" value="Поиск по сайту"/>
<div class="button"><span><input type="submit" value="Поиск" /></span></div>
</form>
Route::get('/search/{str}', "[email protected]");
Answer the question
In order to leave comments, you need to log in
The query parameters are not part of the route, so the route here will be just search, and in the controller itself, you can call $req->q (or $req->input('q')) to get the data you need. Since both the response to the form and the output of this form go through a GET request, in any case, both cases will have to be handled by the same controller method.
It's better to just Route::post('/search', '[email protected]'
).
And take the text from the POST parameter.
This is not true. For search in general it is necessary to use post requests. You need to understand the clear boundaries between get and post.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question