laravel-translatable
  • Introduction
  • Issues
  • Changelog
  • FAQ
  • Installation
  • Package
    • Interface
    • Methods
    • Scopes
    • Fallback locale
    • Locales helper
    • Validation Rule Factory
  • Usage
    • Attributes
    • Forms
    • Pivot Model
    • Custom Validation Rules
Powered by GitBook
On this page

Was this helpful?

  1. Usage

Pivot Model

PreviousFormsNextCustom Validation Rules

Last updated 1 year ago

Was this helpful?

The package trait could also be used on 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.

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;
}
create:role:user:table.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');
});
pivot models