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

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

labrodev/laravel-translatable
=============================

Laravel package providing a reusable trait for multilingual search in Eloquent JSON fields.

v1.0.1(10mo ago)00MITPHPPHP ^8.1 || ^8.2 || ^8.3 || ^8.4

Since Jun 25Pushed 10mo agoCompare

[ Source](https://github.com/labrodev/laravel-translatable)[ Packagist](https://packagist.org/packages/labrodev/laravel-translatable)[ Docs](https://github.com/labrodev/laravel-translatable)[ RSS](/packages/labrodev-laravel-translatable/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (15)Versions (3)Used By (0)

Labrodev Laravel Translatable
=============================

[](#labrodev-laravel-translatable)

A Laravel package that adds JSON-based multilingual support to your Eloquent models. It provides:

- **QueryFieldLocalizer**: Utility to localize JSON fields to the current locale.
- **SearchQueryBuilder**: Trait for case-insensitive, multi-locale JSON field searching.
- **LocaleResolver**: Default resolver that returns `app.locale` and `app.fallback_locale`.

---

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

[](#installation)

Require the package via Composer:

```
composer require labrodev/laravel-translatable
```

Optionally, publish the configuration (if you add a config file later):

```
php artisan vendor:publish --provider="Labrodev\Translatable\TranslatableServiceProvider"
```

> **Note:** No configuration file is required out of the box—this is here for future customization.

---

Usage
-----

[](#usage)

### 1. Localizing JSON Fields

[](#1-localizing-json-fields)

`QueryFieldLocalizer` helps you build locale-specific JSON paths for query fields:

```
use Labrodev\Translatable\Utilities\QueryFieldLocalizer;

// Assume the `title` column contains JSON:
// { "en": "Hello", "es": "Hola" }
$localized = QueryFieldLocalizer::translatableField('title');
// On locale `es`, returns: "title->es"

// Use in query:
$posts = Post::whereRaw("{$localized} = ?", ['Hola'])->get();
```

### 2. Multilingual Search on JSON Columns

[](#2-multilingual-search-on-json-columns)

Add the `SearchQueryBuilder` trait to your Eloquent model:

```
use Illuminate\Database\Eloquent\Model;
use Labrodev\Translatable\Base\Traits\SearchQueryBuilder;

class Article extends Model
{
    use SearchQueryBuilder;

    protected $casts = [
        'titles' => 'array',
    ];
}
```

Perform a case-insensitive search across all configured locales:

```
// Searches "manzana" in `titles` JSON for locales [en, es]
$results = Article::query()
    ->where(function ($q) {
        $this->searchField($q, 'manzana', 'titles');
    })
    ->get();
```

Or chain with existing conditions:

```
$posts = Article::query()
    ->where('published', true)
    ->orWhere(function ($q) {
        $this->searchFieldOr($q, 'orange', 'titles');
    })
    ->get();
```

### 3. Customizing Locales

[](#3-customizing-locales)

By default, locales come from `app.locale` and `app.fallback_locale`. To customize, bind your own `LocaleResolver` implementation:

```
use Labrodev\Translatable\Contracts\LocaleResolver;

$this->app->singleton(LocaleResolver::class, function ($app) {
    return new class implements LocaleResolver {
        public function all(): array
        {
            return ['en', 'fr', 'es'];
        }
    };
});
```

---

Testing
-------

[](#testing)

This package uses Pest with Orchestra Testbench for testing and PHPStan for static analysis. This package uses [Pest](https://pestphp.com/) with [Orchestra Testbench](https://github.com/orchestral/testbench) for testing and [PHPStan](https://https://phpstan.org/) for static analysis

1. Install dependencies:

    ```
    composer install
    ```
2. Run static analysis:

    ```
    composer analyse
    ```
3. Run tests:

    ```
    composer test
    ```

Tests cover:

- `QueryFieldLocalizer::translatableField()` outputs correct JSON path.
- `SearchQueryBuilder` builds proper SQL &amp; bindings for multilingual JSON searches.
- `DefaultLocaleResolverTest` resolve locales array.

---

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

Changelog
---------

[](#changelog)

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

Credits
-------

[](#credits)

- [Labro Dev](https://github.com/labrodev)

Contributing
------------

[](#contributing)

Feel free to open issues or submit pull requests. Check Coding Standards:

- PSR-12
- Strict types enabled

---

License
-------

[](#license)

MIT © Labro Dev

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance53

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

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

2

Last Release

327d ago

### Community

Maintainers

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

---

Tags

eloquent-ormlabrodevlaravellaravel-frameworklaravel-localizationlaravel-modelslaravel-packagelaravel-translatablelaravel-utilsphpphp8query-builderlaraveleloquentlaravel-translatablelaravel-packagetranslatablemodelsquery builderlaravel-utilitylaravel-utilslabrodev

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[dyrynda/laravel-model-uuid

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

4802.8M8](/packages/dyrynda-laravel-model-uuid)[lacodix/laravel-model-filter

A Laravel package to filter, search and sort models with ease while fetching from database.

17649.9k](/packages/lacodix-laravel-model-filter)[relaticle/custom-fields

User Defined Custom Fields for Laravel Filament

15828.6k](/packages/relaticle-custom-fields)[giacomomasseron/laravel-models-generator

Generate Laravel models from an existing database

484.2k](/packages/giacomomasseron-laravel-models-generator)[pursehouse/modeler-laravel-eloquent

Generate model classes for Eloquent in Laravel

112.4k](/packages/pursehouse-modeler-laravel-eloquent)

PHPackages © 2026

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