-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to add several models of a plugin to search? #110
Comments
What went wrong? It is all you need. Maybe share some code so we see where you got stuck. Example for a Tag model: (change the \Event::listen('offline.sitesearch.query', function ($query) {
$controller = \Cms\Classes\Controller::getController() ?? new \Cms\Classes\Controller();
// Search your plugin's contents
$items = YourTagModel
::where('name', 'like', "%${query}%")
->get();
$results = $items->map(function ($item) use ($query, $controller) {
return [
'title' => $item->name,
'text' => 'A tag description'
'url' => $controller->pageUrl('your-tag-detail-page', ['slug' => $item->slug]),
];
});
return [
'provider' => 'Tags',
'results' => $results,
];
});
|
I found the error, some minor misspelling. Works like a charm, thank you so much! So for full clarity for other like me, we just have to repeat the Event Listener for every Model you want a search query for. In case of little blog system it would look like this then.
Multilanguage urls and provider buttons can be achieved like this:
|
I have Blog, with the Models Post, Tag and Category. There is post detail page (succesfully included into the search) and some posts list for articles with a tag and articles in a category.
I would like to let the search list where this tag and category overview pages are.
I did not succeed with repeating the Event Listener and fill in just another model; i guess this needs another approach.
Any tip? :)
Thanx a lot for any help!
The text was updated successfully, but these errors were encountered: