将输入查询添加到搜索功能的路由值 Laravel Scout
Adding input query to route value for search function Laravel Scout
正在尝试为产品设置基本搜索功能。我在对路由参数变量进行排序并将查询字符串传递给搜索函数时遇到问题。
Route::get('/search/{query?}', 'ProductController@searchable');
当我手动输入查询时,这有效 returns 一个查询。
控制器
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' => 'ProductController@searchable', '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 的新手,需要一点帮助。我正在使用 Laravel Scout 和 TNTSearch。
您不需要用户 {wildcard}
进行搜索。我们有 Request
Route::get('search', 'ProductController@searchable');
改为传递 url。
{{ 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() }}
在控制器中简单获取$request->search
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'));
}
正在尝试为产品设置基本搜索功能。我在对路由参数变量进行排序并将查询字符串传递给搜索函数时遇到问题。
Route::get('/search/{query?}', 'ProductController@searchable');
当我手动输入查询时,这有效 returns 一个查询。
控制器
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' => 'ProductController@searchable', '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 的新手,需要一点帮助。我正在使用 Laravel Scout 和 TNTSearch。
您不需要用户 {wildcard}
进行搜索。我们有 Request
Route::get('search', 'ProductController@searchable');
改为传递 url。
{{ 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() }}
在控制器中简单获取$request->search
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'));
}