⛱️Sync Metadata

Synchronize metadata for the model.

🔥 syncMetadata

  • Sync metadata records by replacing all existing ones with new data.

⚠️ cases the operation of this method:

/* 
* This method performs an atomic operation that:
* 1. Deletes all existing metadata records for the model
* 2. Creates new metadata records from the provided data
* 
* The operation will fail and return false if:
* - The provided data is not a valid nested metadata structure
* - The deletion of existing records fails
* 
* If the provided metadata is empty:
* - All existing metadata will be deleted
* - The method will return true
*/ 
// Syntax
$model->syncMetadata(array|Collection $metadata): bool

Example Usage


// Using nested array or Collection return all true
$model->syncMetadata([
    [
        'language' => 'Arabic',
        'theme' => 'auto',
    ],
    [
        'language' => 'Spanish',
        'theme' => 'dark',
    ],
]);

$model->syncMetadata(collect(
    [
        'theme' => 'dark',
        'views' => 767
    ],
    [
        'theme' => 'light',
        'views' => 543
    ],
));

$model->syncMetadata(collect(
    collect([
        'theme' => 'dark',
        'views' => 767
    ]),
    collect([
        'theme' => 'light',
        'views' => 543
    ]),
))



// if metadata is not nested (array, collection) Or empty
$model->syncMetadata([]));  // True;  delete all oldest metadata 
$model->syncMetadata([[]]));  // False; nested but not filled data
$model->syncMetadata([null]));  // False;
$model->syncMetadata(['']));  // False;
$model->syncMetadata(collect([])));  // True;  delete all oldest metadata
$model->syncMetadata([collect([])]));  // False;
$model->syncMetadata(collect([collect([])])));  // False;
$model->syncMetadata(collect([collect([''])])));  // False;
Parameters
Data Type

metadata

array, Collection

Return Type ⇒ Boolean

Last updated