Installation
Last updated
Was this helpful?
Was this helpful?
Schema::create('posts', function(Blueprint $table) {
$table->increments('id');
$table->string('author');
$table->timestamps();
});Schema::create('post_translations', function(Blueprint $table) {
$table->increments('id');
$table->integer('post_id')->unsigned();
$table->string('locale')->index();
$table->string('title');
$table->text('content');
$table->unique(['post_id', 'locale']);
$table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade');
});use Astrotomic\Translatable\Contracts\Translatable as TranslatableContract;
use Astrotomic\Translatable\Translatable;
class Post extends Model implements TranslatableContract
{
use Translatable;
public $translatedAttributes = ['title', 'content'];
protected $fillable = ['author'];
}class PostTranslation extends Model
{
public $timestamps = false;
protected $fillable = ['title', 'content'];
}class ChildPost extends Post
{
protected $table = 'posts';
}use Illuminate\Database\Eloquent\Model;
class ChildPostTranslation extends Model
{
protected $table = 'post_translations';
public $timestamps = false;
protected $fillable = ['title', 'content'];
}class ChildPost extends Post
{
protected $table = 'posts';
protected $translationForeignKey = 'post_id';
}