> For the complete documentation index, see [llms.txt](https://docs.astrotomic.info/laravel-translatable/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.astrotomic.info/laravel-translatable/usage/pivot-model.md).

# Pivot Model

The package trait could also be used on [pivot models](https://laravel.com/docs/5.8/eloquent-relationships#defining-custom-intermediate-table-models) but you should adjust some things to make everything work.

Because the trait introduces a new relation your base model needs a primary key - we will use an auto-increment `id` column. If you want to use an UUID string column or another key you have to set/adjust more things (tell the model and trait which is your primary key, adjust migration ...) but even this is possible.

{% code title="RoleUser.php" %}

```php
use Illuminate\Database\Eloquent\Relations\Pivot;
use Astrotomic\Translatable\Contracts\Translatable as TranslatableContract;
use Astrotomic\Translatable\Translatable;

class RoleUser extends Pivot implements TranslatableContract
{
    use Translatable;

    public $incrementing = true;
}
```

{% endcode %}

{% code title="create:role:user:table.php" %}

```php
Schema::create('role_user', function(Blueprint $table) {
    $table->increments('id');
    $table->integer('user_id')->unsigned();
    $table->integer('role_id')->unsigned();

    $table->unique(['user_id', 'role_id']);
    $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
    $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
});
```

{% endcode %}


---

# 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://docs.astrotomic.info/laravel-translatable/usage/pivot-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.
