PHPackages                             rat.md/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. rat.md/laravel-translatable

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

rat.md/laravel-translatable
===========================

Awesome translatable Laravel Eloquent models (for MySQL, MariaDB, PostgreSQL, SQLite &amp; MongoDB).

0.1.2(7mo ago)17[2 issues](https://github.com/RatMD/laravel-translatable/issues)MITPHPPHP ^8.2

Since Sep 19Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/RatMD/laravel-translatable)[ Packagist](https://packagist.org/packages/rat.md/laravel-translatable)[ Docs](https://rat.md/laravel-translatable)[ RSS](/packages/ratmd-laravel-translatable/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (8)Versions (4)Used By (0)

rat.md/laravel-translatable
===========================

[](#ratmdlaravel-translatable)

Most Laravel “translatable” packages force you to either convert your translatable attributes into a JSON column on the same table (for storing all strings on one place), or requires you to create and maintain a dedicated `{model}_translations` table for each model.

Both approaches work, but they either bloat your base table with JSON logic or force you to manage a growing number of nearly identical tables.

`rat.md/laravel-translatable` takes a different path — inspired by OctoberCMS — by using a **single, shared translations table** for all your models.

Features
--------

[](#features)

- **Support for** MySQL, MariaDB, PostgreSQL, SQlite and MongoDB (Driver-aware querying and sorting).
- **One polymorphic translations table** for everything — no extra migrations per model.
- **Keep your default language clean** in the model’s own columns, exactly where it belongs.
- **Transparent reads and writes** through the model’s attributes, with automatic fallback.

Requirements
------------

[](#requirements)

- PHP ≥ 8.2
- Laravel ≥ 11
- SQLite ≥ 3.35 | MySQL ≥ 8.0 | MariaDB ≥ 10.6 | PostgreSQL ≥ 13.22
- Only required for MongoDB driver (experimental):
    - MongoDB ≥ v7.0 (may work with ≥ v5.0 too)
    - [mongodb/laravel-mongodb ≥ 5.0](https://github.com/mongodb/laravel-mongodb)

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

[](#installation)

Install the package via composer:

```
composer require rat.md/laravel-translatable
```

Publish and run the migrations using:

```
php artisan vendor:publish --tag="laravel-translatable-migrations"
php artisan migrate
```

Publish the configuration file with:

```
php artisan vendor:publish --tag="laravel-translatable-config"
```

Usage
-----

[](#usage)

### Preparing your models

[](#preparing-your-models)

Simply add the `Translatable` trait to your Eloquent models and declare which attributes should support translations. Array-Like attributes must be declared either in your `$casts` or in the package-native `$translatableArrayAttributes` model property.

```
use Rat\Translatable\Concerns\Translatable;

class Post extends Model
{
    use Translatable;

    protected $fillable = ['title', 'content', 'tags'];
    protected $translatable = ['title', 'content', 'tags'];
    protected $casts = [
        'tags' => 'array'
    ];
}
```

### Setting translations

[](#setting-translations)

Set translations in known / familiar ways.

```
// Mass assignment
Post::create([
    'title' => [
        'en' => 'Hello World',
        'de' => 'Hallo Welt',
    ]
]);

// Manual assignment
$post = new Post;
$post->title = 'Hello World';
$post->setTranslation('de', 'title', 'Hallo Welt');
$post->save();

// Manual assignment using withLocale()
$post = new Post;
$post->title = 'Hello World';
$post->withLocale('de', function ($model) {
    $model->title = 'Hallo Welt';
});
```

### Retrieving translations

[](#retrieving-translations)

Access translations directly, use helpers, or switch the application/model locale.

```
$post = Post::first();

// Direct access based on app()->getLocale()
echo $post->title;
app()->setLocale('de');
echo $post->title;

// Manual access
echo $post->getTranslation('de', 'title');
echo $post->getTranslations('de')['title'];

// Access by mutating model locale
$post->locale('de');
echo $post->title;

// Access by cloning model with desired locale
echo $post->in('de')->title;

// Access by using withLocale()
$post->withLocale('de', function ($model) {
    echo $model->title;
});
```

### Querying by locale

[](#querying-by-locale)

Query, filter, and sort your models by translated values across different locales.

Note

`orderByLocale()` is not yet supported for the MongoDB driver. We are actively exploring a clean and efficient implementation. For now, this scope works only with SQL drivers.

```
Post::whereLocale('de', 'title', 'Hallo Welt')->get();
Post::query()->whereLocale('de', 'title', 'Hallo Welt')->get();

Post::whereHasLocale('de')->get();
Post::whereMissingLocale('de')->get(); // or "whereDoesntHaveLocale"

Post::orderByLocale('de', 'title', 'ASC')->get();
```

Testing
-------

[](#testing)

```
./vendor/bin/pest
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

License
-------

[](#license)

Published under MIT License
Copyright © 2024 - 2025 Sam @ rat.md

###  Health Score

30

—

LowBetter than 65% of packages

Maintenance58

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

232d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e4616d6fd140e735e06c7e02e9d59660e6571d0229e67310fc1260a95653246b?d=identicon)[SamBrishes](/maintainers/SamBrishes)

---

Top Contributors

[![SamBrishes](https://avatars.githubusercontent.com/u/106578633?v=4)](https://github.com/SamBrishes "SamBrishes (11 commits)")

---

Tags

eloquentlaravelpackagetranslatablelaraveleloquenttranslatablerat

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/ratmd-laravel-translatable/health.svg)

```
[![Health](https://phpackages.com/badges/ratmd-laravel-translatable/health.svg)](https://phpackages.com/packages/ratmd-laravel-translatable)
```

###  Alternatives

[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[silber/bouncer

Eloquent roles and abilities.

3.6k4.4M25](/packages/silber-bouncer)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
