> For the complete documentation index, see [llms.txt](https://waad-mawlood.gitbook.io/model-metadata/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://waad-mawlood.gitbook.io/model-metadata/basics/markdown-1/use-in-model.md).

# Use in Model

## Setup

```php

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Waad\Metadata\Traits\HasManyMetadata;

class Post extends Model
{
    use HasManyMetadata;  // ----> use this trait
    
    // Enabled Append id with content metadata (default)
    public $metadataNameIdEnabled = true;

    // Custom Append key of id with metadata (default)
    public $metadataNameId = 'id';


    ..........
}

```

***

## Custom Append ID with Run Time

Using example [Get Metadata](/model-metadata/basics/markdown-1/get-metadata.md)

```php

// Enabled Append Id true
$model->setMetadataNameIdEnabled(true)->getMetadata();
/** will return:
* [
*     [
*        'id' => '01jj9s16xcze6byv94fv2f6gc5',   // <<<---------
*        'theme' => 'dark',
*        'language' => 'Arabic',
*     ],
*     [
*        'id' => '01jj9rwvm0g3sypyyb91v5x2gz',   // <<<---------
*        'theme' => 'light',
*        'language' => 'English',
*     ],
* ]
*/

// Enabled Append Id false
$model->setMetadataNameIdEnabled(false)->getMetadata();
/** will return:
* [
*     [
*        'theme' => 'dark',
*        'language' => 'Arabic',
*     ]
* ]
*/


// Enabled Append Id true and changed name of id
$model->setMetadataNameIdEnabled(true)->setMetadataNameId('no')->getMetadata();
/** will return:
* [
*     [
*        'no' => '01jj9s16xcze6byv94fv2f6gc5',    // <<<---------
*        'theme' => 'dark',
*        'language' => 'Arabic',
*     ]
* ]
*/


// Enabled Append Id false and changed name of id
$model->setMetadataNameIdEnabled(false)->setMetadataNameId('no')->getMetadata();
/** will return:
* [
*     [
*        'theme' => 'dark',
*        'language' => 'Arabic',
*     ]
* ]
*/

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://waad-mawlood.gitbook.io/model-metadata/basics/markdown-1/use-in-model.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
