2017-07-07 18 views
1

製品の基本検索機能を設定しようとしています。私は、ルートパラメータ変数をソートし、検索文字列を検索関数に渡すことに問題があります。検索機能のルート値に入力クエリを追加する - laravel

Route::get('/search/{query?}', '[email protected]'); 

これは機能し、クエリを返します。私は手動でクエリを入力します。

コントローラー:

public function searchable($query) 
{ 
    // search database, with result, list on page, with links to products, 
    $products = Product::search($query)->get(); 

    return view('search.index', compact('products')); 

} 

しかし、私はそれがとてもURLから/search?testに来たいと思います。

私のフォームは示しています

{{ Form::open(array('action' => '[email protected]', 'method' => 'get', 'files' => 'false')) }} 
<input type="search" name="search" placeholder="type keyword(s) here" /> 
<button type="submit" class="btn btn-primary">Search</button> 
{{ Form::close() }}` 

は私がlaravelに新しいですので、私は少しの助けを必要としています。私はスカウト(:: search)とTNT検索を使用しています。

答えて

1

検索のために{wildcard}を入力する必要はありません。私たちは、代わりにURLを渡している

Route::get('search', '[email protected]'); 

ためRequestを持っています。

{{ Form::open(array('url' => 'search', 'method' => 'GET', 'files' => 'false')) }} 
    <input type="search" name="search" placeholder="type keyword(s) here" /> 
    <button type="submit" class="btn btn-primary">Search</button> 
{{ Form::close() }} 

シンプルなコントローラでは、私はちょうどなど右のチェーンを取得didntのリクエストオブジェクトで遊んでいた、

public function searchable(Request $request) 
{ 
    // search database, with result, list on page, with links to products, 
    $products = Product::search($request->search)->get(); 

    return view('search.index', compact('products')); 
} 
+0

$request->searchありがとうフェッチすべてのベスト – m33bo

関連する問題