🚀
Model Metadata
  • Introduction V2
  • Requirements
  • Installation
  • Basics
    • Simple Usage
    • HasOneMetadata
      • 😎Use in Model
      • 🎃Create Metadata
      • 🍕Get Metadata
      • ✅Has Metadata
      • 💫Update Metadata
      • ☂️Sync Metadata
      • 💣Delete Metadata
      • 🐙Forget Metadata
    • HasManyMetadata
      • 😐Use in Model
      • 🍔Create Metadata
      • 🍟Get Metadata
      • 🥊Search Metadata
      • 📭Has Metadata
      • 🪭Update Metadata
      • ⛱️Sync Metadata
      • 🪣Delete Metadata
      • 🧽Forget Metadata
Powered by GitBook
On this page
  • 🔥 getMetadata
  • 🔥 getMetadataCollection
  • 🔥 getKeyMetadata
  1. Basics
  2. HasOneMetadata

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.

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

keys

array, Collection, string, int, null

Return Type ⇒ array


🔥 getMetadataCollection

It's an Alias getMetadata but retun as Collection

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


🔥 getKeyMetadata

Get individual metadata value by key.

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

Example Usage


$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',
* ]
*/

Parameters
Data Types

key

string, int

Return Type ⇒ array, string, int, float, bool, null

PreviousCreate MetadataNextHas Metadata

Last updated 4 months ago

🍕