Making-Websites-With-October-CMS
Making-Websites-With-October-CMS copied to clipboard
Search on multiple models with sitesearch
Is it possible to search on several models with different rules?
An example with actors and films is it possible to search on both?
I only find search in one model like this:
$items = Models\Movie::where('name', 'like', "%${query}%") ->orWhere('description', 'like', "%${query}%") ->get();
You can do something like this:
$this['videos'] = WatchLearn\Videos\Models\Video::whereHas('series', function ($query) {
$query->where('slug', '=', $this->param('slug'))->where('published', true);
})->orderBy('created_at', 'asc')->get();
This is an example from my site so I'm basically getting all the videos that belong to a specific series, and getting that series by slug. So my video is a model, and the Series is a different model. And they of course have a relation.
Hope this helps.