PHPackages                             vershub/laraveltranslations - 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. vershub/laraveltranslations

ActiveLibrary

vershub/laraveltranslations
===========================

laravel package for translatable models

v1.0.1(1y ago)064MITPHPPHP &gt;=8.2

Since Dec 26Pushed 1y agoCompare

[ Source](https://github.com/Vershub/laraveltranslations)[ Packagist](https://packagist.org/packages/vershub/laraveltranslations)[ RSS](/packages/vershub-laraveltranslations/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

Laravel Translations
====================

[](#laravel-translations)

 **This lightweight Laravel package enables you to eager load models along with their translations in the specified language, efficiently preventing the N+1 query problem. Additionally, it allows you to retrieve a single translation (instead of an array) without unnecessarily loading extra models into memory..**

 [ ![Latest Stable Version](https://camo.githubusercontent.com/449618d9a61df7bc455b261bf73ab7547136b24c86dc05dc1c9d3f70df055a1a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f766572736875622f6c61726176656c7472616e736c6174696f6e732e7376673f7374796c653d666c61742d737175617265) ](https://packagist.org/packages/vershub/laraveltranslations) [ ![Total Downloads](https://camo.githubusercontent.com/0eff5de28f928f11d7be3af0ea8e2483750eb0531ef77fd989a346c64184d618/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f766572736875622f6c61726176656c7472616e736c6174696f6e732e7376673f7374796c653d666c61742d737175617265) ](https://packagist.org/packages/vershub/laraveltranslations) [ ![License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265) ](LICENSE.md)

🚀 Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require vershub/laraveltranslations
```

🛠️ Usage
--------

[](#️-usage)

### 1. Create a Translatable Model

[](#1-create-a-translatable-model)

Extend the `TranslatableModel` class and implement the required abstract methods:

```
namespace App\Models;

use Vershub\LaravelTranslations\TranslatableModel;

class CarBrand extends TranslatableModel
{
    protected $fillable = ['name'];

    protected function getTranslationModel(): string
    {
        return CarBrandTranslation::class;
    }

    protected function getForeignKeyForTranslation(): string
    {
        return 'car_brand_id';
    }
}
```

### 2. Create a Translation Model

[](#2-create-a-translation-model)

The translation model should be a standard Eloquent model:

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class CarBrandTranslation extends Model
{
    protected $fillable = ['locale_code', 'name', 'description'];
}
```

Example of translation table migration:

```
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCarBrandTranslationsTable extends Migration
{
    public function up()
    {
        Schema::create('car_brand_translations', function (Blueprint $table) {
            $table->id();
            $table->foreignId('car_brand_id')->constrained()->cascadeOnDelete();
            $table->string('locale_code');
            $table->string('name');
            $table->text('description')->nullable();
            $table->timestamps();
        });
    }

    public function down()
    {
        Schema::dropIfExists('car_brand_translations');
    }
}
```

### 3. Use the `withTranslation` Scope

[](#3-use-the-withtranslation-scope)

#### Retrieve translations for the current locale

[](#retrieve-translations-for-the-current-locale)

```
use App\Models\CarBrand;

$carBrands = CarBrand::withTranslation()->get();

foreach ($carBrands as $carBrand) {
    echo $carBrand->translation->name;
}
```

#### Retrieve translations for a specific locale

[](#retrieve-translations-for-a-specific-locale)

```
use App\Models\CarBrand;

$carBrands = CarBrand::withTranslation('fr')->get();

foreach ($carBrands as $carBrand) {
    echo $carBrand->translation->name;
}
```

#### Select specific columns from translations table

[](#select-specific-columns-from-translations-table)

```
use App\Models\CarBrand;

$carBrands = CarBrand::withTranslation('fr:id,locale_code,name,description')->get();
```

⚙️ Customization
----------------

[](#️-customization)

### Override the Locale Code Column

[](#override-the-locale-code-column)

By default, the package uses `locale_code`. You can change this by publishing the config file and change the value of `locale_code_column` key:

```
return [
    'locale_code_column' => 'locale_code'
];

```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance44

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

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 ~16 days

Total

2

Last Release

486d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/71bdd5537593c570811c9f9dda99db318821e374abac844cb8be528cdae149e2?d=identicon)[Vershub](/maintainers/Vershub)

---

Top Contributors

[![Vershub](https://avatars.githubusercontent.com/u/39310986?v=4)](https://github.com/Vershub "Vershub (5 commits)")

### Embed Badge

![Health badge](/badges/vershub-laraveltranslations/health.svg)

```
[![Health](https://phpackages.com/badges/vershub-laraveltranslations/health.svg)](https://phpackages.com/packages/vershub-laraveltranslations)
```

PHPackages © 2026

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