# Create Metadata

Metadata supports all data types in PHP that can store null, empty, string, int, float and array

## 🔥 `createMetadata`

```php
// Syntax
$model->createMetadata(array|Collection): ?\Waad\Metadata\Models\Metadata;
```

To create metadata you can use the createMetadata function, which is capable of handling various data types such as strings, integers, floats, arrays, and null values. Below is an example demonstrating how metadata can be structured and assigned to a company object:

#### Example Usage

```php
$company->createMetadata([
    'language' => 'English',       // string data type
    'is_visible' => true,          // boolean data type
    'phone' => '',                 // empty string
    'slug' => null,                // null value
    'theme' => 'dark',             // string data type
    'views' => 100,                // integer data type
    'rating' => 4.5,               // float data type
    'sports' => ['football', 'basketball'],  // array data type
]);

// return Metadata Model or null 
```

| Parameters                               | Data Type                                              |
| ---------------------------------------- | ------------------------------------------------------ |
| <mark style="color:red;">metadata</mark> | <mark style="color:purple;">`array, Collection`</mark> |

{% hint style="info" %} <mark style="color:green;">Return Type ⇒</mark> <mark style="color:orange;">\Waad\Metadata\Models\Metadata</mark> <mark style="color:green;">,</mark> <mark style="color:orange;">null</mark>
{% endhint %}

***

## 🔥 `addKeysMetadata`

This method adds new metadata if it does not exist or adds new values with keys if metadata exists.

```php
// Syntax
// @param $keys array|Collection|string|int|null
// @param $value array|Collection|string|int|float|bool|null
$model->addKeysMetadata($keys, $value = null): bool
```

#### Example Usage `addKeysMetadata`&#x20;

```php

// Method: addKeysMetadata
// The addKeysMetadata method returns a boolean value.
// Use `addKeysMetadata` method for multiple or individual keys

// ++++++++++ array Keys ++++++++++
$status = $company->addKeysMetadata([
    'language' => 'English',
    'is_visible' => true,
]);

// ++++++++++ Collection Keys ++++++++++
$status = $company->addKeysMetadata(collect([
    'language' => 'English',
    'is_visible' => true,
]));

// ++++++++++ Individual Key ++++++++++
$status = $company->addKeysMetadata(keys: 'language', value: 'English');
$status = $company->addKeysMetadata(keys: 7, value: 'some value');
$status = $company->addKeysMetadata('tags', ['action', 'drama']);
$status = $company->addKeysMetadata('location', ['lat'=> 44.4324, 'lng' => 43.5346]);
$status = $company->addKeysMetadata('tags', collect(['action', 'drama']));
$status = $company->addKeysMetadata('phone', null);
$status = $company->addKeysMetadata('address', '');
$status = $company->addKeysMetadata('is_public', true);
$status = $company->addKeysMetadata('visits', 501);
$status = $company->addKeysMetadata('exchange', 7.35);

```

<table><thead><tr><th width="218">Parameters Method</th><th>Accept Data Type</th><th data-hidden></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><td></td></tr><tr><td><mark style="color:red;">value</mark></td><td><mark style="color:purple;"><code>array, Collection, string, int, float, bool, null</code></mark></td><td></td></tr></tbody></table>

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

***

## 🔥 `addKeyMetadata`&#x20;

{% hint style="warning" %} <mark style="color:yellow;">It's Alias of the \`</mark><mark style="color:blue;">addKeysMetadata</mark><mark style="color:yellow;">\` method used for adding Individual Key</mark>
{% endhint %}

```php
// Syntax
// @param $key string|int|null
// @param $value array|Collection|string|int|float|bool|null
$model->addKeyMetadata($key, $value = null): bool
```

#### Example Usage `addKeyMetadata`&#x20;

```php

// Use `addKeyMetadata` method for individual key

$status = $company->addKeyMetadata(key: 'language', value: 'English');
$status = $company->addKeyMetadata(key: 7, value: 'some value');
$status = $company->addKeyMetadata(key: 'length', value: '');
$status = $company->addKeyMetadata(key: 'length', value: null);
$status = $company->addKeyMetadata(key: 'rating', value: 5.4);
$status = $company->addKeyMetadata(key: 'length', value: 175);
$status = $company->addKeyMetadata(key: 'actors', value: ['john', 'smith']);
$status = $company->addKeyMetadata('location', ['lat'=> 44.4324, 'lng' => 43.5346]);
$status = $company->addKeyMetadata(key: 'actors', value: collect(['john', 'smith']));

```

<table><thead><tr><th width="218">Parameters Method</th><th>Accept Data Type</th><th data-hidden></th></tr></thead><tbody><tr><td><mark style="color:red;">key</mark></td><td><mark style="color:purple;"><code>string, int, null</code></mark></td><td></td></tr><tr><td><mark style="color:red;">value</mark></td><td><mark style="color:purple;"><code>array, Collection, string, int, float, bool, null</code></mark></td><td></td></tr></tbody></table>

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


---

# 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/create-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.
