πŸ”Create Metadata

Creating and adding metadata

Metadata supports all data types in PHP that can store null, empty, string, int, float and array

πŸ”₯ createMetadata

// Syntax
$model->createMetadata(array|Collection): \Waad\Metadata\Models\Metadata;

To create metadata you can use the createMetadata function, which is capable of handling various data types such as strings, integers, floats, arrays, and null values. Below is an example demonstrating how metadata can be structured and assigned to a company object:

Example Usage

    
// Usage array input
$model->createMetadata([
    'language' => 'English',       // string data type
    'is_visible' => true,          // boolean data type
    'phone' => '',                 // empty string
    'slug' => null,                // null value
    'theme' => 'dark',             // string data type
    'views' => 100,                // integer data type
    'rating' => 4.5,               // float data type
    'sports' => ['football', 'basketball'],  // array data type
]);

// Usage Collection input
$model->createMetadata(collect(['language' => 'English', 'theme' => 'dark']));
Parameters
Data Type

metadata

array, Collection

Return Type β‡’ \Waad\Metadata\Models\Metadata


πŸ”₯ createManyMetadata

Example Usage

Parameters
Data Type

metadatas

array, Collection

Return Type β‡’ Collection, false


πŸ”₯ addKeysMetadataById

This method adds new values with keys if metadata exists.

Example Usage

Parameters Method
Accept Data Type

id

string

keys

array, Collection, string, int, null

value

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

Return Type β‡’ Boolean


πŸ”₯ addKeyMetadataById

Example Usage

Parameters Method
Accept Data Type

id

string

key

string, int, null

value

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

Return Type β‡’ Boolean

Last updated