# Has Metadata

## 🔥 `hasMetadata`

* Check if a record of the relationship exists.
* regardless of whether the metadata content is empty or not.

```php
// Syntax
$model->hasMetadata(): bool
```

***

## 🔥 `hasFilledMetadata`

* Check if a record of the relationship exists.
* &#x20;Check metadata column contains data that is not empty

```php
// Syntax
$model->hasFilledMetadata(): bool
```

***

## 🔥 `hasKeyMetadata`

* Check if the metadata contains a specific key.
* regardless of whether the key content is empty.

```php
// Syntax
$model->hasKeyMetadata(string|int|null $key): bool
```

***

## 🔥 `hasAllKeysMetadata`

* Check if the metadata contains all specified keys.
* regardless of whether all keys content is empty.

```php
// Syntax
// @param $keys array|Collection|string|int|null
$model->hasAllKeysMetadata($keys): bool
```

***

## 🔥 `hasAnyKeysMetadata`

* Check if metadata contains any of the specified keys.
* regardless of whether all keys content is empty.

```php
// Syntax
// @param $keys array|Collection|string|int|null
$model->hasAnyKeysMetadata($keys): bool
```

***

## 🐞 Examples

```php

// ++++++++++++++++++ hasMetadata ++++++++++++++++++
$model->hasMetadata();
/** Returns true if metadata record exists, false otherwise */


// ++++++++++++++++++ hasFilledMetadata ++++++++++++++++++
$model->hasFilledMetadata();
/** 
* Returns true if metadata exists and is not empty
* Returns false if:
*  - No metadata record exists
*  - Metadata exists but is null
*  - Metadata exists but is an empty array/collection
*/


// ++++++++++++++++++ hasKeyMetadata ++++++++++++++++++
$model->hasKeyMetadata('name');
$model->hasKeyMetadata(7);
$model->hasKeyMetadata(null); // returns false
/** Returns true if the key exists in metadata */


// ++++++++++++++++++ hasAllKeysMetadata ++++++++++++++++++
$model->hasAllKeysMetadata(['name', 'age']); // true if BOTH keys exist
$model->hasAllKeysMetadata(collect(['name', 'age'])); // accepts Collection
$model->hasAllKeysMetadata('name'); // true if 'name' exists
$model->hasAllKeysMetadata(8); // check list array
$model->hasAllKeysMetadata([5, 6]);
$model->hasAllKeysMetadata(null); // returns false


// ++++++++++++++++++ hasAnyKeysMetadata ++++++++++++++++++
$model->hasAnyKeysMetadata(['name', 'age']); // true if Any keys exist
$model->hasAnyKeysMetadata(collect(['name', 'age'])); // accepts Collection
$model->hasAnyKeysMetadata('name'); // true if 'name' exists
$model->hasAnyKeysMetadata(8); // check list array
$model->hasAnyKeysMetadata([5, 6]);
$model->hasAnyKeysMetadata(null); // returns false

```

***

## 📚 Summary

* `hasAllKeysMetadata()` - Returns true only if ALL specified keys exist
* `hasKeyMetadata()` - Convenience method for checking a single key, internally uses `hasAllKeysMetadata()`
* `hasAnyKeysMetadata()` - Returns true if ANY of the specified keys exist


---

# Agent Instructions: 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:

```
GET https://waad-mawlood.gitbook.io/model-metadata/basics/markdown/has-metadata.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
