Making-Websites-With-October-CMS icon indicating copy to clipboard operation
Making-Websites-With-October-CMS copied to clipboard

Search on multiple models with sitesearch

Open rvgmartins opened this issue 6 years ago • 1 comments

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();

rvgmartins avatar Feb 09 '19 23:02 rvgmartins

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.

ivandoric avatar Feb 14 '19 10:02 ivandoric