Get metadata column as Array.
Retrieves metadata values from the metadata column. If keys are provided only the specified keys will be returned.
// Syntax
$model->getMetadata(array|Collection|string|int|null $keys = null): array
Example Usage Without Keys Parameter
// 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
// +++++++++++ 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
// Syntax
// @param $keys array|Collection|string|int|null
$model->getMetadataCollection($keys = null): Collection
Get individual metadata value by key.
// Syntax
$model->getKeyMetadata(string|int $key): string|int|float|bool|array|null
$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',
* ]
*/