R
R
root092015-11-10 20:09:34
Laravel
root09, 2015-11-10 20:09:34

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>

routes to this url: /search?q=test
how to make routes for this url?
or how to submit a form to a url like this?:
Route::get('/search/{str}', "[email protected]");

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
Timofey, 2015-11-11
@root09

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.

M
Mikhail Osher, 2015-11-10
@miraage

It's better to just Route::post('/search', '[email protected]').
And take the text from the POST parameter.

A
Alex Wells, 2015-11-12
@Alex_Wells

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 question

Ask a Question

731 491 924 answers to any question