# Update Metadata

The [laravel-model-metadata](https://github.com/waadmawlood/laravel-model-metadata) package allows you to easily update metadata associated with your models.

## 🔥 `updateMetadata`

```php
// Syntax
$model->updateMetadata(array|Collection $metadata): bool
```

#### Example Usage

```php
$company->createMetadata(['theme' => 'dark']);
$company->updateMetadata(['theme' => 'light']);

// Using array
$company->updateMetadata(['theme' => 'auto', 'year' => 1997]);
// The updated metadata will be:
[
    'theme' => 'auto',
    'year' => 1997,
];


// Using Collection
$company->updateMetadata(collect(['theme' => 'dark', 'year' => 1998]));
// The updated metadata will be:
[
    'theme' => 'dark',
    'year' => 1998,
];
```

| Parameters                               | Data Types                                             |
| ---------------------------------------- | ------------------------------------------------------ |
| <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;">Boolean</mark>
{% endhint %}



***



## 🔥 `updateKeysMetadata`

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

#### Example Usage

```php
    
// +++++++++++++++++ array Keys +++++++++++++++++
$company->updateKeysMetadata(['theme' => 'light', 'year' => 2000]);
// will be: ['theme' => 'light', 'year' => 2000];

$company->updateKeysMetadata(['theme' => 'dark']);
// will be: ['theme' => 'dark', 'year' => 2000];

// +++++++++++++++++ Collection Keys +++++++++++++++++
$company->updateKeysMetadata(collect(['theme' => 'auto', 'year' => 2021]));
// will be: ['theme' => 'auto', 'year' => 2021];

// ++++++++++ Individual Key ++++++++++
$company->updateKeysMetadata('year', 1997);
// will be: ['theme' => 'auto', 'year' => 1997];

$company->updateKeysMetadata('year', '');
// will be: ['theme' => 'auto', 'year' => ''];

$company->updateKeysMetadata('year', null);
// will be: ['theme' => 'auto', 'year' => null];

$company->updateKeysMetadata('theme', ['light', 'dark']);
// will be: ['theme' => [0 => 'light', 1 => 'dark'], 'year' => null];

```

<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><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></tr></tbody></table>

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



***



## 🔥 `updateKeyMetadata`&#x20;

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

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

#### Example usage

```php
$company->updateKeyMetadata('year', 1997);
$company->updateKeyMetadata('theme', 'auto');
$company->updateKeyMetadata('year', '');
$company->updateKeyMetadata('year', null);
$company->updateKeyMetadata('theme', ['light', 'dark']);
$company->updateKeyMetadata('theme', collect(['light', 'dark']));
$company->updateKeyMetadata('year', 34.7);
```

<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, null</code></mark></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></tr></tbody></table>

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