Skip to content

Instantly share code, notes, and snippets.

@nunomaduro
Created December 19, 2018 12:39
Show Gist options
  • Save nunomaduro/fc3751807c7bcae7f067e072b1d15397 to your computer and use it in GitHub Desktop.
Save nunomaduro/fc3751807c7bcae7f067e072b1d15397 to your computer and use it in GitHub Desktop.
Searching aggregators
<?php
$models = App\Search\News::search('Star Trek')->get();
echo get_class($models[0]); // "App\Article"
echo get_class($models[1]); // "App\Comment"
$results = App\Search\News::search('Star Trek')->raw();
/*
{
"hits":[
{
"id":1,
"title": "Article title",
"slug": "article-title",
"content": "Article content",
"objectID":"App\\Article::1",
...
},
{
"id": 1,
"content": "Comment content",
"objectID": "App\\Comment::1",
...
},
],
...
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment