> For the complete documentation index, see [llms.txt](https://docs.opensoutheners.com/oss/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.opensoutheners.com/oss/laravel-scout-advanced-meilisearch/multisearch.md).

# MultiSearch

Meilisearch's multi-index search support for Laravel.

Since Meilisearch 1.0 releases this MultiSearch feature Laravel Scout doesn't support out of the box, this feature adds support to transform multiple type of search results into its [Eloquent models](https://laravel.com/docs/eloquent) in a [Laravel Collection](https://laravel.com/docs/collections).

### Usage

To get search results in a controller see the example below.

```php
<?php

namespace App\Http\Controllers;

use OpenSoutheners\LaravelScoutAdvancedMeilisearch\MultiSearch;
use App\Models\Film;
use App\Models\Serie;

class SearchController extends Controller
{
    public function __invoke(Request $request)
    {
        return app(MultiSearch::class)
            ->by(Film::class, $request->q)
            ->by(Serie::class, $request->q)
            ->search();
    }
}
```

### Usage with globally searchable models

This can also be used with a single search query to be performed to all models marked as globally searchable using the [Model attribute](/oss/laravel-scout-advanced-meilisearch/index-settings.md).

<pre class="language-php"><code class="lang-php">&#x3C;?php

namespace App\Models;

use Laravel\Scout\Searchable;
use OpenSoutheners\LaravelScoutAdvancedMeilisearch\Attributes\ScoutSearchableSettings;

#[ScoutSearchableSettings(searchable: ['title', 'description'], <a data-footnote-ref href="#user-content-fn-1">globallySearchable: true</a>)]
class Film extends Model
{
    use Searchable;
    
    // Model logic...
}
</code></pre>

After adding the `globallySearchable` parameter on all the relevant models the controller should now look like this:

```php
<?php

namespace App\Http\Controllers;

use OpenSoutheners\LaravelScoutAdvancedMeilisearch\MultiSearch;

class SearchController extends Controller
{
    public function __invoke(Request $request)
    {
        return app(MultiSearch::class)->search($request->input("q", ""));
    }
}
```

This query will be performed to all the models with the `globallySearchable` on the attribute.

[^1]: Important attribute parameter


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.opensoutheners.com/oss/laravel-scout-advanced-meilisearch/multisearch.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
