πGet Metadata
π₯ getMetadata
getMetadata Get all metadata records associated with the model as an array
// Syntax
$model->getMetadata(): arrayExample Usage
// If metadataNameIdEnabled is true, each metadata record will include its ID
class Post extends Model
{
use HasManyMetadata;
public $metadataNameIdEnabled = true;
public $metadataNameId = 'id';
...........
}
$post->getMetadata();
/** will return:
* [
* [
* 'id' => '01jj9s16xcze6byv94fv2f6gc5', // <<<---------
* 'theme' => 'dark',
* 'language' => 'Arabic',
* ],
* [
* 'id' => '01jj9rwvm0g3sypyyb91v5x2gz', // <<<---------
* 'theme' => 'light',
* 'language' => 'English',
* ],
* ]
*/
π₯ getMetadataCollection
getMetadataCollectionIt's an Alias getMetadata but return as Collection
π₯ getMetadataById
getMetadataByIdGet a specific metadata record using its ID.
Retrieves metadata values from the metadata column. If keys are provided only the specified keys will be returned.
Example Usage Without Keys Parameter
Example Usage With Keys Parameter
Parameters
Data Types
id
string
keys
array, Collection, string, int, null
π₯ getKeyMetadataById
getKeyMetadataByIdGet a single value from a metadata record by its ID and key.
Example Usage
Parameters
Data Types
id
string
key
string, int
Last updated