Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
42 lines (31 sloc) 1.44 KB

Pivot Model

The package trait could also be used on pivot 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-tabs %} {% code-tabs-item title="RoleUser.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-tabs-item %} {% endcode-tabs %}

{% code-tabs %} {% code-tabs-item title="create_role_user_table.php" %}

Schema::create('role_user', function(Blueprint $table) {
    $table->unique(['user_id', 'role_id']);

{% endcode-tabs-item %} {% endcode-tabs %}

You can’t perform that action at this time.