💫Update Metadata

The laravel-model-metadata package allows you to easily update metadata associated with your models.

🔥 updateMetadata

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

Example Usage

$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

metadata

array, Collection

Return Type ⇒ Boolean


🔥 updateKeysMetadata

// 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

    
// +++++++++++++++++ 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];
Parameters
Data Types

keys

array, Collection, string, int, null

value

array, Collection, string, int, float, bool, null

Return Type ⇒ Boolean


🔥 updateKeyMetadata

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

Example usage

$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);
Parameters
Data Types

key

string, int, null

value

array, Collection, string, int, float, bool, null

Return Type ⇒ Boolean

Last updated