If it's helpful, I can show you the whole boot function code here:
public function boot()
{
\Event::listen('offline.sitesearch.query', function ($query) {
// Search your plugin's contents
$product = Models\Product::where(function($q) {
$q->where('product_validation', '>', now())
->orWhereNull('product_validation');
})->where(function($q) {
$q->where('product_name', 'like', "%${query}%")
->orWhere('product_tags', 'like', "%${query}%")
->orWhere('product_description', 'like', "%${query}%");
})
->get();
// Now build a results array
$productResults = $product->map(function ($item) use ($query) {
// If the query is found in the title, set a relevance of 2
$relevance = mb_stripos($item->title, $query) !== false ? 2 : 1;
if($item->product_img)
{
return [
'title' => $item->product_name,
'text' => $item->product_validation,
'url' => '/product/' . $item->product_slug,
'thumb' => $item->product_img, // Instance of System\Models\File
'relevance' => $relevance // higher relevance results in a higher
// position in the results listing
// 'meta' => 'data', // optional, any other information you want
// to associate with this result
// 'model' => $item, // optional, pass along the original model
];
} else {
return [
'title' => $item->product_name,
'text' => $item->product_validation,
'url' => '/product/' . $item->product_slug,
'relevance' => $relevance // higher relevance results in a higher
// position in the results listing
// 'meta' => 'data', // optional, any other information you want
// to associate with this result
// 'model' => $item, // optional, pass along the original model
];
}
});
return [
'provider' => '', // The badge to display for this result
'results' => $productResults,
];
});