# Get Metadata

## 🔥 `getMetadata`

Get metadata column as Array.

Retrieves metadata values from the metadata column. If keys are provided only the specified keys will be returned.

```php
// Syntax
$model->getMetadata(array|Collection|string|int|null $keys = null): array
```

#### Example Usage Without Keys Parameter

```php

// Create Metadata
$model->createMetadata([
    'language' => 'English',
    'is_visible' => true, 
    'theme' => 'dark',
    'year' => 2019,
    'rating' => 4.5,
    'tags' => ['action', 'drama'],  // array data type
]);


// Using Without keys Parameter
$model->getMetadata();
/**
* Will return array:
* [
*    'language' => 'English',
*    'is_visible' => true,
*    'theme' => 'dark',
*    'year' => 2019,
*    'rating' => 4.5,
*    'tags' => [
*        0 => 'action',
*        1 => 'drama',
*    ]
* ]
*/

```

#### Example Usage With Keys Parameter

```php
    
// +++++++++++ Using Keys array, Collection +++++++++++
$model->getMetadata(['theme', 'language']);
$model->getMetadata(collect(['theme', 'language']));
/**
* Will return array:
* [
*    'theme' => 'dark',
*    'language' => 'English',
* ]
*/


// +++++++++++ Using Individual Key +++++++++++
$model->getMetadata('theme');
/**
* Will return array:
* [
*    'theme' => 'dark',
* ]
*/

$model->getMetadata('tags');
/**
* Will return array:
* [
*    'tags' => [
*        0 => 'action',
*        1 => 'drama',
*    ]
* ]
*/

$model->getMetadata(3); // if metadata saved list array
$model->getMetadata(null); // will return all metadata as array

```

<table><thead><tr><th width="186">Parameters</th><th>Data Types</th></tr></thead><tbody><tr><td><mark style="color:red;">keys</mark></td><td><mark style="color:purple;"><code>array, Collection, string, int, null</code></mark></td></tr></tbody></table>

{% hint style="info" %} <mark style="color:green;">Return Type ⇒</mark> <mark style="color:orange;">array</mark>
{% endhint %}

***

## 🔥 getMetadataCollection

{% hint style="success" %}
It's an Alias `getMetadata` but retun as `Collection`&#x20;
{% endhint %}

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

***

## 🔥 `getKeyMetadata`

Get individual metadata value by key.

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

#### Example Usage

```php

$model->getKeyMetadata('language'); // return: 'English'
$model->getKeyMetadata('is_visible'); // return: true
$model->getKeyMetadata('theme'); // return: 'dark'
$model->getKeyMetadata('year'); // return: 2019
$model->getKeyMetadata('rating'); // return: 4.5
$model->getKeyMetadata('not_exists'); // return null
$model->getKeyMetadata(3); // return (4th index) item in list array

$model->getKeyMetadata('tags');
/**
* Will return:
* [
*    0 => 'action',
*    1 => 'drama',
* ]
*/


```

<table><thead><tr><th width="186">Parameters</th><th>Data Types</th></tr></thead><tbody><tr><td><mark style="color:red;">key</mark></td><td><mark style="color:purple;"><code>string, int</code></mark></td></tr></tbody></table>

{% hint style="info" %} <mark style="color:green;">Return Type ⇒</mark> <mark style="color:orange;">array, string, int, float, bool, null</mark>
{% endhint %}
