# Search

> Laravel Rest Api exposes the search endpoint which is dedicated to access data for your frontend users.

## Usage

Here is a quick look at what you can do:

```json
// (POST) api/posts/search
{
  "search": {
    "text": {
      "value": "my full text search"
    },
    "scopes": [
      {"name": "withTrashed", "parameters": [true]}
    ],
    "filters": [
      {
        "field": "id", "operator": ">", "value": 1, "type": "or"
      },
      {
        "nested": [
          {"field": "user.id", "operator": "<", "value": 2},
          {"field": "id", "operator": ">", "value": 100, "type": "or"}
        ]
      }
    ],
    "sorts": [
      {"field": "user_id", "direction": "desc"},
      {"field": "id", "direction": "asc"}
    ],
    "selects": [
      {"field": "id"}
    ],
    "includes": [
      {
        "relation": "posts",
        "filters": [
          {"field": "id", "operator": "in", "value": [1, 3]}
          ],
        "limit": 2
      },
      {
        "relation": "posts",
        "alias": "draftPosts",
        "filters": [
          {"field": "published", "value": false}
        ]
      },
      {
        "relation": "user",
        "filters": [
          {
            "field": "languages.pivot.boolean",
            "operator": "=",
            "value": true
          }
        ]
      }
    ],
    "aggregates": [
      {
        "relation": "stars",
        "type": "max",
        "field": "rate",
        "alias": "approved_max_stars",
        "filters": [
          {"field": "approved", "value": true}
        ]
      }
    ],
    "instructions": [
      {
        "name": "odd-even-id",
        "fields": [
          { "name": "type", "value": "odd" }
        ]
      }
    ],
    "gates": ["create", "view"],
    "page": 2,
    "limit": 10
  }
}
```

### Specifications

<table>
<thead>
  <tr>
    <th>
      <strong>
        Key
      </strong>
    </th>
    
    <th>
      <strong>
        Type
      </strong>
    </th>
    
    <th>
      <strong>
        Required
      </strong>
    </th>
    
    <th>
      <strong>
        Default
      </strong>
    </th>
    
    <th>
      <strong>
        Description
      </strong>
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <strong>
        Text
      </strong>
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        text.value
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      X
    </td>
    
    <td>
      
    </td>
    
    <td>
      The text you want to search
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Scopes
      </strong>
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        scopes.name
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      X
    </td>
    
    <td>
      
    </td>
    
    <td>
      The name of the scope
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        scopes.parameters
      </code>
    </td>
    
    <td>
      <code>
        array
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      The parameters associated with the scope
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Filters
      </strong>
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        filters.field
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      when not nested
    </td>
    
    <td>
      
    </td>
    
    <td>
      The name of the field
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        filters.operator
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      <code>
        =
      </code>
    </td>
    
    <td>
      The field operator
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        filters.value
      </code>
    </td>
    
    <td>
      <code>
        mixed
      </code>
    </td>
    
    <td>
      when not nested
    </td>
    
    <td>
      
    </td>
    
    <td>
      The value you want to filter with
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        filters.type
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      <code>
        and
      </code>
    </td>
    
    <td>
      The filter condition type
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        filters.nested
      </code>
    </td>
    
    <td>
      <code>
        array
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      The nested parameters
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Sorts
      </strong>
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        sorts.field
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      X
    </td>
    
    <td>
      
    </td>
    
    <td>
      The name of the field
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        sorts.direction
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      <code>
        asc
      </code>
    </td>
    
    <td>
      The direction in which results should be sorted
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Selects
      </strong>
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        selects.field
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      X
    </td>
    
    <td>
      
    </td>
    
    <td>
      The name of the field
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Includes
      </strong>
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        includes.relation
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      X
    </td>
    
    <td>
      
    </td>
    
    <td>
      The relation you are querying
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        includes.alias
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      The key the relation is returned under, allowing the same relation to be included multiple times
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        includes.other
      </code>
    </td>
    
    <td>
      <code>
        mixed
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      <code>
        50
      </code>
    </td>
    
    <td>
      You can specify all the arguments in the current page such as <code>
        filters
      </code>
      
      , <code>
        limit
      </code>
      
      , <code>
        scopes
      </code>
      
      , etc except include
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Aggregates
      </strong>
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        aggregates.relation
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      X
    </td>
    
    <td>
      
    </td>
    
    <td>
      The relation you are querying
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        aggregates.type
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      X
    </td>
    
    <td>
      
    </td>
    
    <td>
      The type of the aggregates you want to use in: <code>
        min
      </code>
      
      , <code>
        max
      </code>
      
      , <code>
        avg
      </code>
      
      , <code>
        sum
      </code>
      
      , <code>
        count
      </code>
      
       and <code>
        exists
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        aggregates.field
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      when type is not <code>
        exists
      </code>
      
       or <code>
        count
      </code>
    </td>
    
    <td>
      <code>
        *
      </code>
    </td>
    
    <td>
      The field you want to execute your aggregate on
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        aggregates.alias
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      The alias given for the aggregate
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        aggregates.filters
      </code>
    </td>
    
    <td>
      <code>
        array
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      You can specify all the arguments for the <code>
        filters
      </code>
      
       section
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Instructions
      </strong>
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        instructions.name
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      X
    </td>
    
    <td>
      
    </td>
    
    <td>
      The instruction <code>
        uriKey
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        instructions.fields
      </code>
    </td>
    
    <td>
      <code>
        array
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      The fields provided with the instruction. Use instruction listing to see which ones can be provided.
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Pagination
      </strong>
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        page
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      1
    </td>
    
    <td>
      The actual page
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        limit
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      50
    </td>
    
    <td>
      The maximum number of results
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Gates
      </strong>
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
    
    <td>
      
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        gates
      </code>
    </td>
    
    <td>
      <code>
        array
      </code>
    </td>
    
    <td>
      
    </td>
    
    <td>
      <span>
        
      </span>
    </td>
    
    <td>
      The gates you want to get in: <code>
        create
      </code>
      
      , <code>
        view
      </code>
      
      , <code>
        update
      </code>
      
      , <code>
        delete
      </code>
      
      , <code>
        restore
      </code>
      
       and <code>
        forceDelete
      </code>
    </td>
  </tr>
</tbody>
</table>

### Response

As a response you'll receive the filtered records and related metadata:

```json
{
  "current_page": 1,
  "data": [
    {
      "id": 1,
      "name": "Lou West",
      "gates": {
        "authorized_to_view": true,
        "authorized_to_update": true,
        "authorized_to_delete": true,
        "authorized_to_restore": true,
        "authorized_to_force_delete": true
      }
    },
    {
      "id": 2,
      "name": "Bridget Wilderman",
      "gates": {
        "authorized_to_view": true,
        "authorized_to_update": true,
        "authorized_to_delete": true,
        "authorized_to_restore": true,
        "authorized_to_force_delete": true
      }
    }
  ],
  "from": 1,
  "last_page": 1,
  "per_page": 50,
  "to": 2,
  "total": 2,
  "meta": {
    "gates": {
      "authorized_to_create": true
    }
  }
}
```

### Scopes

Scopes corresponds to [Laravel's scopes](https://laravel.com/docs/eloquent#query-scopes). You'll need to [specify them in your resource](/2.x/resources/exposed-data#scopes) first to allow their usage.

Use it as the following:

```json
// (POST) api/posts/search
{
  "search": {
    "scopes": [
      {"name": "withTrashed", "parameters": [true]}
    ]
  }
}
```

### Filters

Filters in Laravel Rest Api are the means by which you specify the data you want to retrieve, based on specified fields.
All fields specified here must be defined in the [fields method of your resource](/2.x/resources/exposed-data#fields) first.

Use it as the following:

```json
// (POST) api/posts/search
{
  "search": {
    "filters": [
      {
        "field": "id", "operator": ">", "value": 1
      }
    ]
  }
}
```

Field is the column you want to interact with.

Operator must be one of these:

- =
- !=
- >
- >=
- <
- <=
- like
- not like
- in
- not in

#### Distant Field

You may specify fields related to relationships by specifying the relationship(s):

```json
// (POST) api/posts/search
{
  "search": {
    "filters": [
      {
        "field": "languages.label",
        "operator": "=",
        "value": "fr"
      }
    ]
  }
}
```

#### Type

In many cases you want to condition your multiple filters using an "OR" operation instead of an "AND" one.

You can achieve this by specifying the type of the filter:

```json
// (POST) api/posts/search
{
  "search": {
    "filters": [
      {"field": "user.id", "operator": "<", "value": 2},
      {"field": "id", "operator": ">", "value": 100, "type": "or"}
    ]
  }
}
```

Here the query will look if the user related id is less than 2 or if the id of the post is greater than 100.

#### Pivot Filtering

When you deal with a relation that has a pivot such as the `BelongsToMany` relation, you might want to filter in the pivot table.

You can achieve this by doing:

```json
// (POST) api/posts/search
{
  "search": {
    "filters": [
      {
        "field": "languages.pivot.boolean",
        "operator": "=",
        "value": true
      }
    ]
  }
}
```

#### Nested Filtering

You may want to prioritize your condition depending on the filter type because an "AND" operation takes advantage of an "OR" operation.

You can achieve this by doing:

```json
// (POST) api/posts/search
{
  "search": {
    "filters": [
      {
        "field": "id", "operator": "=", "value": 159, "type": "or"
      },
      {
        "field": "name", "operator": "like", "value": "%super post%", "type": "or"
      },
      {
        "nested": [
          {"field": "user.id", "operator": "<", "value": 2},
          {"field": "id", "operator": ">", "value": 100, "type": "or"}
        ]
      }
    ]
  }
}
```

Here, Laravel Rest Api will look if the id of the posts is 159 OR the name like "%super post%" OR (the user id is less than 2 and the id of the post is greater than 100)

##### Nesting depth

By default, filters may only nest one level deep. You can control how deep filters are allowed to nest into each other with the `search.max_nesting_depth` option in your `config/rest.php` file:

```php
[
    // ...
    'search' => [
        'max_nesting_depth' => 1, // The maximum depth filters may nest into each other
    ]
    // ...
]
```

A value of `1` allows a single group of nested filters (the historical behavior), while higher values allow groups nested inside other groups. Keep this value modest: deeply nested filters build large, complex boolean queries.

<note>

Nesting stays disabled when performing a [full text search](#text), regardless of this setting.

</note>

### Sorts

Sorts allows you to specify in which order you want to sort your results.

All fields specified here must be defined in the [fields method of your resource](/2.x/resources/exposed-data#fields) first.

```json
// (POST) api/posts/search
{
  "search": {
    "sorts": [
      {"field": "user_id", "direction": "desc"},
      {"field": "id", "direction": "asc"}
    ]
  }
}
```

#### Default sort

By default, Laravel Rest Api provides a default sort based on `id` descending. If you want to change this, please see the [configuration](/2.x/resources/exposed-data#default-sort)

### Selects

In some cases, you may want to specify the columns you want to select because it makes your API faster to not query unnecessary data.
By default, Laravel Rest Api will query all your `fields`. You cannot query columns that are not present in the `fields` method.

You can achieve this by doing:

```json
// (POST) api/posts/search
{
  "search": {
    "selects": [
      {"field": "id"},
      {"field": "title"}
    ]
  }
}
```

### Includes

In order to limit the number of queries made to the API, Laravel Rest Api allows you to query distant relationships through a single endpoint.

You can achieve this by doing:

```json
// (POST) api/posts/search
{
  "search": {
    "includes": [
      {
        "relation": "posts"
      }
    ]
  }
}
```

#### More powerful include

In order to make the include operation much more powerful, Laravel Rest Api allows to specify each argument on this page except `include` to avoid caveats.

This allows you to do the following:

```json
// (POST) api/posts/search
{
  "search": {
    "includes": [
      {
        "relation": "posts",
        "filters": [
          {"field": "id", "operator": "in", "value": [1, 3]}
        ],
        "limit": 2
      }
    ]
  }
}
```

#### Aliasing an include

By default a relation is returned under its own name, which means it can only appear once in the response. Provide an `alias` to choose the key it is returned under, and the same relation can be included several times with different constraints:

```json
// (POST) api/posts/search
{
  "search": {
    "includes": [
      {
        "relation": "comments",
        "alias": "approvedComments",
        "filters": [
          {"field": "approved", "value": true}
        ]
      },
      {
        "relation": "comments",
        "alias": "pendingComments",
        "filters": [
          {"field": "approved", "value": false}
        ]
      }
    ]
  }
}
```

Each post then carries an `approvedComments` and a `pendingComments` key instead of a single `comments` key. Including a relation both natively and under an alias is allowed, and both keys are returned.

The alias is used verbatim as the response key, so it is not converted to snake case the way a relation name is.

<warning>

Because the alias becomes a key of the response, it is validated:

- it must look like an identifier, matching `^[A-Za-z_][A-Za-z0-9_]*$`, and be at most 255 characters
- it must be unique across the includes of the same level
- it may not collide with a field of the resource, one of its relations, or the [gates](/2.x/digging-deeper/gates) key
- it is not allowed on a dotted relation path such as `posts.comments`

Anything else returns a `422` response.

</warning>

A dotted path has no single level the alias could key into, so alias the relation through a nested `includes` entry instead:

```json
// (POST) api/users/search
{
  "search": {
    "includes": [
      {
        "relation": "posts",
        "includes": [
          {
            "relation": "comments",
            "alias": "approvedComments",
            "filters": [
              {"field": "approved", "value": true}
            ]
          }
        ]
      }
    ]
  }
}
```

### Aggregates

If you don't know what an aggregate is, please have a look at the [Laravel documentation](https://laravel.com/docs/queries#aggregates) first.

Laravel Rest Api supports all Laravel's aggregates, here is a quick look at how to specify your aggregate:

```json
// (POST) api/posts/search
{
  "search": {
    "aggregates": [
      {
        "relation": "comments",
        "type": "avg",
        "field": "stars"
      }
    ]
  }
}
```

Here we are getting the average stars for the comments linked to the posts.

The type could be one of these:

- min
- max
- avg
- sum
- count
- exists

<warning>

For the `exists` and `count` operation you must not specify the field since these aggregates don't base themselves on a column.

</warning>

#### Aggregates aliases

You may optionally define an alias for your aggregate using the `alias` method. This allows you to customize the name of the aggregate column in the response, instead of relying on Laravel's default naming.

```json
// (POST) api/posts/search
{
  "search": {
    "aggregates": [
      {
        "relation": "comments",
        "type": "avg",
        "field": "stars",
        "alias": "average_stars"
      }
    ]
  }
}
```

#### Aggregates filtering

For more complex aggregates, Laravel Rest Api allows you to specify filters. These filters are the same as [the basic ones](/2.x/endpoints/search#filters).

```json
// (POST) api/posts/search
{
  "search": {
    "aggregates": [
      {
        "relation": "comments",
        "type": "avg",
        "field": "stars",
        "filters": [
          {"field": "approved", "value": true}
        ]
      }
    ]
  }
}
```

### Instructions

Instructions is a way for api builder to define strong query operations. They'll be defined in the [resource details](/2.x/endpoints/details) when exposed.

Here is how to specify an instruction:

```json
// (POST) api/posts/search
{
  "search": {
    "instructions": [
      {
        "name": "odd-even-id"
      }
    ]
  }
}
```

Here we are getting the posts that have an even id.

The specified name is the `uriKey` of the instruction.

#### Instructions fields

For more complex instructions, Laravel Rest Api allows you to specify fields. You can have full access to the fields and validation in the [resource details](/2.x/endpoints/details).

```json
// (POST) api/posts/search
{
  "search": {
    "instructions": [
      {
        "name": "odd-even-id",
        "fields": [
          {"field": "type", "value": "odd"}
        ]
      }
    ]
  }
}
```

### Pagination

You might either want to limit the data you are querying or to specify a page to load data by sequence.
All limits specified here must be defined in the [limits method of your resource](/2.x/resources/exposed-data#limits) first.

You can achieve this by doing:

```json
// (POST) api/posts/search
{
  "search": {
    "page": 2,
    "limit": 10
  }
}
```

### Gates

If you want to retrieve permissions on the models you are getting, you need to specify the gates you want to get. Use this with care this can slow down you application queries.

Be aware before that Gates needs to be enabled in order to be retrieved. Have a look at [Automatic Gates](/2.x/digging-deeper/gates) if you need detail.

The gates could be one of these:

- create
- view
- update
- delete
- restore
- forceDelete

```json
// (POST) api/posts/search
{
  "search": {
    "gates": ["create", "view"]
  }
}
```

### Text

If you want to specify a full text search you'll need to use the text argument. First be sure you [activated full text search for the resource](/2.x/digging-deeper/full-text-search).

```json
// (POST) api/posts/search
{
  "search": {
    "text": {
      "value": "my text search"
    }
  }
}
```

<note>

When `text` is provided but its `value` is empty or `null`, the endpoint returns an empty paginated result immediately, without querying the search engine.

</note>

#### Impacts

When using full text search, some restrictions happens to the query:

<table>
<thead>
  <tr>
    <th>
      <strong>
        Key
      </strong>
    </th>
    
    <th>
      <strong>
        Changes
      </strong>
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <strong>
        Scopes
      </strong>
    </td>
    
    <td>
      
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        scopes.name
      </code>
    </td>
    
    <td>
      Not allowed
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        scopes.parameters
      </code>
    </td>
    
    <td>
      Not allowed
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Filters
      </strong>
    </td>
    
    <td>
      
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        filters.field
      </code>
    </td>
    
    <td>
      take scout fields instead of fields in resource detail
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        filters.operator
      </code>
    </td>
    
    <td>
      <code>
        =
      </code>
      
      /<code>
        in
      </code>
      
      /<code>
        not in
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        filters.type
      </code>
    </td>
    
    <td>
      Not allowed
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        filters.nested
      </code>
    </td>
    
    <td>
      Not allowed
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Sorts
      </strong>
    </td>
    
    <td>
      
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        sorts.field
      </code>
    </td>
    
    <td>
      uses Scout fields instead of fields defined in resource details
    </td>
  </tr>
</tbody>
</table>

#### Text search with trashed models

Because the Laravel Scout Builder differs from Eloquent, `withTrashed` is not a scope when performing text search.<br />


Instead, control trashed handling via the `text.trashed` option:

- "with"  → include both non-trashed and trashed records
- "only"  → include only trashed records
- omitted → exclude trashed records (default)

```json
// (POST) api/posts/search
{
  "search": {
    "text": {
      "value": "my text search",
      "trashed": "with"
    }
  }
}
```
