> ## Documentation Index
> Fetch the complete documentation index at: https://docs.eloquentfiltering.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Has

export const type_0 = "$has"

## Definition

### Including Relations Fields

```php theme={null}
Filter::relation('comments', [FilterType::HAS])->includeRelationFields();
```

### With Defining Sub Filters

```php theme={null}
Filter::relation('comments', [FilterType::HAS],
    Filter::only(
        Filter::field('content', [FilterType::LIKE])
    )
);
```

## Array/Object Structure

<ParamField body="type" type="string" required>
  <code>
    {type_0}
  </code>
</ParamField>

<ParamField body="target" type="string" required />

<ParamField body="value" type="array" />

<ParamField body="value.*" type="array">
  Any other filter
</ParamField>

## Example

```php theme={null}
$filter = [
    'type'   => '$has',
    'target' => 'comments',
    'value'  => [
        [
            'type'   => '$like',
            'target' => 'content',
            'value'  => 'awesome',
        ]
    ]
];
```

```php theme={null}
$sql = Project::filter([$filter])->toRawSql();
```

### SQL

```sql theme={null}
select
  *
from
  "projects"
where
  exists (
    select
      *
    from
      "comments"
    where
      "projects"."id" = "comments"."project_id"
      and "comments"."content" LIKE '%awesome%'
  )
```

## Modifiers

None available.
