我将laravel 5.6与以下软件包结合使用以实现基本的搜索功能
https://github.com/nicolaslopezj/searchable
在搜索页面上,我的表单为
<form>
<div class="input-group input-group-sm">
<div class="left-inner-addon">
<i class="fas fa-map-marker-alt text-light2"></i>
<input type="text" class="form-control form-control-gray" id="txtPlaces" name="location" value="" placeholder="Enter your location">
</div>
<input type="text" class="form-control form-control-gray col-md-6" name="search" value="" placeholder="Enter provider name or specialization">
<div class="input-group-append">
<button class="btn btn-danger" type="button"><strong><i class="fas fa-arrow-right"></i></strong></button>
</div>
</div>
</form>
在我的控制器中,我有
public function index(Request $request)
{
$categories = ProviderCategory::where('status', 1)->get();
$start_search = microtime('s');
$searchterm = $request->input('search');
if ($request->has('search')) {
$providers = Provider::search($searchterm)->where('status', 1)->with('category')->paginate(10);
} else {
$providers = Provider::where('status', 1)->with('category')->paginate(10);
}
$stop_search = microtime('s');
$time_search = ($stop_search - $start_search);
return view('frontend.providers.index', compact('providers', 'searchterm', 'time_search', 'categories'));
}
在我的模型中,我根据包装文档添加了以下内容
protected $searchable = [
/**
* Columns and their priority in search results.
* Columns with higher values are more important.
* Columns with equal values have equal importance.
*
* @var array
*/
'columns' => [
'providers.name' => 10,
'providers.qualification' => 10,
'providers.specialization' => 10,
'providers.about' => 10,
'providers.address' => 10,
'providers.phone' => 10,
'providers.email' => 10,
'providers.website' => 10,
'providers.timings' => 10,
'providers.experience' => 10,
'providers.fee' => 10,
'providers.languages' => 10,
'providers.meta_title' => 10,
'providers.meta_keywords' => 10,
'providers.meta_description' => 10,
'provider_categories.name' => 10,
'provider_categories.description' => 10,
],
'joins' => [
'provider_categories' => ['providers_categories.id', 'providers.category_id']
],
];
当我在搜索输入中搜索任何关键字时,它会按预期工作。但作为即时消息,也使用另一个输入的位置(使用工作正常的谷歌地图)。在上面的代码中也如何搜索位置。
我的意思是请求是否具有搜索和位置显示结果。
我真的被困在这里,需要帮助