M
M
matros972019-04-08 08:14:31
Laravel
matros97, 2019-04-08 08:14:31

How to pass a search query route?

Good afternoon, I'm doing a search for the site, tell me how to transfer the search query to the address bar.
Here is the search form

{!! Form::open(['url' => route('search')]) !!}
                <input id="appendedInputButton" size="16" name="search" type="text" placeholder="Поиск..."><button class="btn" type="submit"><i class="icon-search"></i></button>
                {!! Form::close() !!}

This is how this method handles the search
public function search(Request $request)
    {
        $search = '%'.$request->search.'%';

        $posts = Post::where('text', 'like', $search)->paginate(env('PAGINAV'));

        $title = 'Резальтаты поиска по запросу: '.$request->search; 

        return view('search', ['posts' => $posts, 'title' => $title]);
    }

Search route
Route::post('search/{search?}', '[email protected]')->name('search');

Now the search is like this mysite.loc/search
and you need to do it like this mysite.loc/search/Search query
How to do this

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kuznetsov, 2019-04-08
@dima9595

Use GET instead of POST.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question