PHPackages                             flobbos/laravel-translatable-db - 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. flobbos/laravel-translatable-db

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

flobbos/laravel-translatable-db
===============================

A Laravel package for multilingual models

2.0.0(1mo ago)53.4k↓88.3%2MITPHPPHP ^8.1CI passing

Since Apr 7Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/Flobbos/laravel-translatable)[ Packagist](https://packagist.org/packages/flobbos/laravel-translatable-db)[ RSS](/packages/flobbos-laravel-translatable-db/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)Dependencies (7)Versions (21)Used By (2)

Laravel Translatable DB
=======================

[](#laravel-translatable-db)

[![Laravel Translatable DB](img/laravel-translatable.png)](img/laravel-translatable.png)

Database-backed translated Eloquent attributes, resolved by a language id instead of a locale string.

This package started as a fork of [dimsav/laravel-translatable](https://github.com/dimsav/laravel-translatable). It only reads translated attributes. It does not manage CRUD forms or translation persistence.

Compatibility
-------------

[](#compatibility)

LaravelPackage13.x2.x12.x2.x11.x2.x10.x2.x5.3-9.x1.xLaravel 10 support means the package requires PHP `^8.1`. Laravel itself may require a higher PHP version for newer framework releases.

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

[](#installation)

```
composer require flobbos/laravel-translatable-db:^2.0
```

Laravel auto-discovery registers the service provider. Publish the config only when you need to override defaults:

```
php artisan vendor:publish --provider="Flobbos\TranslatableDB\TranslatableDBServiceProvider"
```

Tables
------

[](#tables)

Example for a translated `Country` model:

```
Schema::create('languages', function (Blueprint $table) {
    $table->id();
    $table->string('locale')->unique();
    $table->string('name');
});

Schema::create('countries', function (Blueprint $table) {
    $table->id();
    $table->string('code')->unique();
    $table->timestamps();
});

Schema::create('country_translations', function (Blueprint $table) {
    $table->id();
    $table->foreignId('country_id')->constrained()->cascadeOnDelete();
    $table->foreignId('language_id')->constrained()->cascadeOnDelete();
    $table->string('name');

    $table->unique(['country_id', 'language_id']);
});
```

If your default language lives on the main model table, add the translated column there and enable native fallback on the model:

```
public $fallbackAttributes = ['name'];
```

Then set:

```
'native_mode' => true,
```

Models
------

[](#models)

```
namespace App\Models;

use Flobbos\TranslatableDB\TranslatableDB;
use Illuminate\Database\Eloquent\Model;

class Country extends Model
{
    use TranslatableDB;

    public $translatedAttributes = ['name'];
    public $fallbackAttributes = ['name'];

    protected $fillable = ['code'];
}
```

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class CountryTranslation extends Model
{
    public $timestamps = false;

    protected $fillable = ['language_id', 'name'];
}
```

By convention, `Country` uses `CountryTranslation`. Override it when needed:

```
public $translationModel = CountryText::class;
```

Usage
-----

[](#usage)

```
$country = Country::where('code', 'gr')->first();

app()->setLocale('en');
echo $country->name; // Greece

app()->setLocale('de');
echo $country->name; // Griechenland

echo $country->getAttribute('name:2'); // Explicit language id
```

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

[](#configuration)

Important defaults:

```
'use_db' => true,
'language_model' => App\Models\Language::class,
'locale_key' => 'language_id',
'locale_column' => 'locale',
'use_fallback' => true,
'fallback_locale_id' => 1,
'middleware_default' => false,
'to_array_always_loads_translations' => false,
```

With database mode enabled, the middleware resolves `app()->getLocale()` through your language model and stores the matching id on the request.

With database mode disabled, configure languages directly:

```
'use_db' => false,
'language_array' => [
    'de' => ['name' => 'Deutsch', 'language_id' => 1],
    'en' => ['name' => 'English', 'language_id' => 2],
],
```

Middleware
----------

[](#middleware)

The middleware is no longer pushed globally by default in 2.x.

Register it where translated route content needs automatic language id resolution:

```
use Flobbos\TranslatableDB\Middleware\LanguageIdentification;

Route::middleware(LanguageIdentification::class)->group(function () {
    // translated routes
});
```

If you really want the old global behavior:

```
'middleware_default' => true,
```

Polymorphic Translations
------------------------

[](#polymorphic-translations)

Implement `PolyTrans` and set the morph name:

```
namespace App\Models;

use Flobbos\TranslatableDB\Contracts\PolyTrans;
use Flobbos\TranslatableDB\TranslatableDB;
use Illuminate\Database\Eloquent\Model;

class Country extends Model implements PolyTrans
{
    use TranslatableDB;

    public $translationModel = Translation::class;

    protected $translationForeignKey = 'translatable';
}
```

Testing
-------

[](#testing)

```
composer test
```

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance90

Actively maintained with recent releases

Popularity25

Limited adoption so far

Community26

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 84.5% 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 ~178 days

Recently: every ~664 days

Total

20

Last Release

45d ago

Major Versions

1.3.6 → v20.x-dev2017-07-13

1.4.7 → 2.0.02026-07-06

PHP version history (3 changes)1PHP &gt;=5.6.0

1.4.6PHP &gt;=7.1.0

2.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/74704c23d1a3ea66e1ddd18de4e90635ea4a2c28838e72ad49ba947694f7988e?d=identicon)[Flobbos](/maintainers/Flobbos)

---

Top Contributors

[![dimsav](https://avatars.githubusercontent.com/u/1785686?v=4)](https://github.com/dimsav "dimsav (317 commits)")[![sdebacker](https://avatars.githubusercontent.com/u/134503?v=4)](https://github.com/sdebacker "sdebacker (10 commits)")[![johannesschobel](https://avatars.githubusercontent.com/u/9431350?v=4)](https://github.com/johannesschobel "johannesschobel (7 commits)")[![easteregg](https://avatars.githubusercontent.com/u/188798?v=4)](https://github.com/easteregg "easteregg (4 commits)")[![Hyleeh](https://avatars.githubusercontent.com/u/5340560?v=4)](https://github.com/Hyleeh "Hyleeh (3 commits)")[![Flobbos](https://avatars.githubusercontent.com/u/21225457?v=4)](https://github.com/Flobbos "Flobbos (3 commits)")[![tintamarre](https://avatars.githubusercontent.com/u/409734?v=4)](https://github.com/tintamarre "tintamarre (2 commits)")[![lan0](https://avatars.githubusercontent.com/u/7386264?v=4)](https://github.com/lan0 "lan0 (2 commits)")[![alfhen](https://avatars.githubusercontent.com/u/5700924?v=4)](https://github.com/alfhen "alfhen (2 commits)")[![ben-nsng](https://avatars.githubusercontent.com/u/5063993?v=4)](https://github.com/ben-nsng "ben-nsng (2 commits)")[![plmarcelo](https://avatars.githubusercontent.com/u/205708?v=4)](https://github.com/plmarcelo "plmarcelo (2 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (2 commits)")[![sebastianjung](https://avatars.githubusercontent.com/u/17472892?v=4)](https://github.com/sebastianjung "sebastianjung (2 commits)")[![shadoWalker89](https://avatars.githubusercontent.com/u/1449151?v=4)](https://github.com/shadoWalker89 "shadoWalker89 (2 commits)")[![ShortlyMAB](https://avatars.githubusercontent.com/u/4995979?v=4)](https://github.com/ShortlyMAB "ShortlyMAB (2 commits)")[![zoransa](https://avatars.githubusercontent.com/u/921796?v=4)](https://github.com/zoransa "zoransa (1 commits)")[![barryvdh](https://avatars.githubusercontent.com/u/973269?v=4)](https://github.com/barryvdh "barryvdh (1 commits)")[![boydcl](https://avatars.githubusercontent.com/u/6942044?v=4)](https://github.com/boydcl "boydcl (1 commits)")[![Frozire](https://avatars.githubusercontent.com/u/6813614?v=4)](https://github.com/Frozire "Frozire (1 commits)")[![hannesvdvreken](https://avatars.githubusercontent.com/u/1410358?v=4)](https://github.com/hannesvdvreken "hannesvdvreken (1 commits)")

---

Tags

laravellanguagedatabasetranslation

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[api-platform/laravel

API Platform support for Laravel

58190.1k21](/packages/api-platform-laravel)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.6k31.8M162](/packages/laravel-cashier)[laravel/scout

Laravel Scout provides a driver based solution to searching your Eloquent models.

1.7k57.2M684](/packages/laravel-scout)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45844.8k1](/packages/pressbooks-pressbooks)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5226.7k](/packages/simplestats-io-laravel-client)

PHPackages © 2026

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