PHPackages                             davesweb/laravel-translatable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. davesweb/laravel-translatable

ActiveLibrary[Database &amp; ORM](/categories/database)

davesweb/laravel-translatable
=============================

Add translations to Eloquent models

0.1.0(4y ago)126MITPHPPHP ^8.0

Since Nov 3Pushed 4y ago1 watchersCompare

[ Source](https://github.com/davesweb/laravel-translatable)[ Packagist](https://packagist.org/packages/davesweb/laravel-translatable)[ RSS](/packages/davesweb-laravel-translatable/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

Laravel Translatable
====================

[](#laravel-translatable)

Add translation to Laravel Models by adding a translation model and a translation database table.

Installation
------------

[](#installation)

Via composer

```
composer require davesweb/laravel-translatable
```

Configuration
-------------

[](#configuration)

- Add the `Davesweb\LaravelTranslatable\Traits\HasTranslations` trait to the model you want to translate.
- Create a translation model which holds the translatable attributes, but instead of extending the Laravel `Model`class, extend the `Davesweb\LaravelTranslatable\Models\TranslationModel` class.
- Create a migration to create the database table for your translation model. There are also commands available for generating these models and migrations for you.

As long as the names of the translation model and the foreign key column follow the naming conventions, the package will automatically find the correct models and set the correct relations.

The name of the translation model should be the same as the model that is being translated with the suffix `Translation`, for example `App\Page` and `App\PageTranslation`.

The name of the foreign key column should be the name of the model that is being translated in snake case, suffixed with the name of the primary key. For instance `page_id`. If your model names differ from te naming convention you can specify them yourself on the models. For the model to be translated, add a `$translation` property.

```
