Install package

Add the package in your composer.json by executing the command.

composer require astrotomic/laravel-translatable


We copy the configuration file to our project.

php artisan vendor:publish --tag=translatable

After this you will have to configure the locales your app should use.

'locales' => [
'es' => [
'MX', // mexican spanish
'CO', // colombian spanish

There isn't any restriction for the format of the locales. Feel free to use whatever suits you better, like "eng" instead of "en", or "el" instead of "gr". The important is to define your locales and stick to them.

That's the only configuration key you have to adjust. All the others have a working default value and are described in the configuration file itself.


In this example, we want to translate the model Post. We will need an extra table post_translations:

Schema::create('posts', function(Blueprint $table) {
Schema::create('post_translations', function(Blueprint $table) {
$table->unique(['post_id', 'locale']);


The translatable model Post should use the trait Astrotomic\Translatable\Translatable. The default convention for the translation model is PostTranslation. The array $translatedAttributes contains the names of the fields being translated in the PostTranslation model.

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'];