> For the complete documentation index, see [llms.txt](https://prismic-eloquent.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://prismic-eloquent.gitbook.io/docs/models.md).

# Models

## Creating models

A model represents a content type of your Prismic environment. Each model should extends the abstract base model from the package.

For example; We have a content type called 'page':

```
namespace App;

use RobinDrost\PrismicEloquent\Model;

class Page extends Model {}
```

This base setup is already enough to query the api for your documents.

{% hint style="info" %}
You can overwrite the static method **`getTypeName`** to specify the content type. Prismic Eloquent will use the name of the class by default and convert camelCase to snake\_case.
{% endhint %}

### Alter fields

Your model can implement methods that are called when a field is called. For example a 'title' field can be changed like:

```
namespace App;

use RobinDrost\PrismicEloquent\Model;

class Page extends Model 
{
    public function getTitleField($value)
    {
        return $value . ' suffix for my title';
    }
}
```

You model will now use `getTitleField` when `$page->title` is called.

### Local scopes

Local scopes like used in the normal Eloquent models are also available.

```
namespace App;

use RobinDrost\PrismicEloquent\Model;

class Page extends Model 
{
    public function scopeTestTitle($query)
    {
        $query->where('title, 'test');
    }
    
    public function scopeFilterByRequest($query, Request $request, $field)
    {
        if ($request->filled($field)) {
            $query->where($field, $request->get($field);
        }
    }
}

Page::testTitle()->first();
Page::filterByRequest($request, 'field_name')->first();
```

### Camel case fields

You can access your model field by camelCase. Prismic Eloquent will automatically change camel case to snake case since this is the default in Prismic.

For example:

```
$page->myAwesomeTitle

// actual field name in Prismic
// my_awesome_title
```

{% hint style="info" %}
You can disable this behaviour by overwriting the **`fieldsToSnakeCase`** property on your model.
{% endhint %}


---

# 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, and the optional `goal` query parameter:

```
GET https://prismic-eloquent.gitbook.io/docs/models.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
