🚀
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
  • 🔥 updateMetadataById
  • 🔥 updateKeysMetadataById
  • 🔥 updateKeyMetadataById
  1. Basics
  2. HasManyMetadata

Update Metadata

🔥 updateMetadataById

// Syntax
$model->updateMetadataById(string $id, array|Collection $metadata): bool

Example Usage

$company->createMetadata(['theme' => 'dark']);
$company->updateMetadataById($id, ['theme' => 'light']);

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


// Using Collection
$company->updateMetadataById($id, collect(['theme' => 'dark', 'year' => 1998]));
// The updated metadata will be:
[
    'theme' => 'dark',
    'year' => 1998,
];
Parameters
Data Types

id

string

metadata

array, Collection

Return Type ⇒ Boolean


🔥 updateKeysMetadataById

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

Example Usage

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

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

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

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

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

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

$company->updateKeysMetadataById($id, 'theme', ['light', 'dark']);
// will be: ['theme' => [0 => 'light', 1 => 'dark'], 'year' => null];
Parameters
Data Types

id

string

keys

array, Collection, string, int, null

value

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

Return Type ⇒ Boolean


🔥 updateKeyMetadataById

It's an Alias of the `updateKeysMetadataById` method used for updating Individual Key

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

Example usage

$company->updateKeyMetadataById($id, 'year', 1997);
$company->updateKeyMetadataById($id, 'theme', 'auto');
$company->updateKeyMetadataById($id, 'year', '');
$company->updateKeyMetadataById($id, 'year', null);
$company->updateKeyMetadataById($id, 'theme', ['light', 'dark']);
$company->updateKeyMetadataById($id, 'theme', collect(['light', 'dark']));
$company->updateKeyMetadataById($id, 'year', 34.7);
Parameters
Data Types

id

string

key

string, int, null

value

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

Return Type ⇒ Boolean

PreviousHas MetadataNextSync Metadata

Last updated 4 months ago

🪭