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

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

spatie/laravel-translatable
===========================

A trait to make an Eloquent model hold translations

6.13.0(2mo ago)2.4k23.0M—6.7%29820MITPHPPHP ^8.3CI passing

Since Apr 8Pushed 3w ago24 watchersCompare

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

READMEChangelog (10)Dependencies (7)Versions (83)Used By (20)

 [   ![Logo for laravel-translatable](https://camo.githubusercontent.com/75ec55cb65932073fc27782f4b57804763ad7cbd4a76fbeaefb024b83bdbb883/68747470733a2f2f7370617469652e62652f7061636b616765732f6865616465722f6c61726176656c2d7472616e736c617461626c652f68746d6c2f6c696768742e77656270)  ](https://spatie.be/open-source?utm_source=github&utm_medium=banner&utm_campaign=laravel-translatable)A trait to make Eloquent models translatable
============================================

[](#a-trait-to-make-eloquent-models-translatable)

[![Latest Version on Packagist](https://camo.githubusercontent.com/84243101d1a1e96438193f844bb47df7297d24f0a55c966c439a8c9c27d72ebd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d7472616e736c617461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-translatable)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![GitHub Workflow Status](https://camo.githubusercontent.com/048af3144b94f1606e000d15cecbdfc3fb938138ecb87fef7642f4502adf2598/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d7472616e736c617461626c652f72756e2d74657374732e796d6c)](https://camo.githubusercontent.com/048af3144b94f1606e000d15cecbdfc3fb938138ecb87fef7642f4502adf2598/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d7472616e736c617461626c652f72756e2d74657374732e796d6c)[![Total Downloads](https://camo.githubusercontent.com/cf6bb0932610b395888b6e428a7355558aa08ac7d93a9533d4eff5f06509470b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d7472616e736c617461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-translatable)

This package contains a trait `HasTranslations` to make Eloquent models translatable. Translations are stored as json. There is no extra table needed to hold them.

```
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\Attributes\Translatable;
use Spatie\Translatable\HasTranslations;

#[Translatable('name', 'description')]
class NewsItem extends Model
{
    use HasTranslations;

    // ...
}
```

The attribute accepts a variadic list of column names, so you can pass as many as you need.

Alternatively, you can declare the translatable attributes via a public `$translatable` property:

```
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;

class NewsItem extends Model
{
    use HasTranslations;

    public $translatable = ['name'];
}
```

When both the property and the attribute are present, their values are merged and deduplicated.

After the trait is applied on the model you can do these things:

```
$newsItem = new NewsItem;
$newsItem
   ->setTranslation('name', 'en', 'Name in English')
   ->setTranslation('name', 'nl', 'Naam in het Nederlands')
   ->save();

$newsItem->name; // Returns 'Name in English' given that the current app locale is 'en'
$newsItem->getTranslation('name', 'nl'); // returns 'Naam in het Nederlands'

app()->setLocale('nl');
$newsItem->name; // Returns 'Naam in het Nederlands'

$newsItem->getTranslations('name'); // returns an array of all name translations

// You can translate nested keys of a JSON column using the -> notation
// First, add the path to the $translatable array, e.g., 'meta->description'
$newsItem
   ->setTranslation('meta->description', 'en', 'Description in English')
   ->setTranslation('meta->description', 'nl', 'Beschrijving in het Nederlands')
   ->save();

$attributeKey = 'meta->description';
$newsItem->$attributeKey; // Returns 'Description in English'
$newsItem->getTranslation('meta->description', 'nl'); // Returns 'Beschrijving in het Nederlands'
```

Also providing scoped queries for retrieving records based on locales

```
// Returns all news items with a name in English
NewsItem::whereLocale('name', 'en')->get();

// Returns all news items with a name in English or Dutch
NewsItem::whereLocales('name', ['en', 'nl'])->get();

// Returns all news items that has name in English with value `Name in English`
NewsItem::query()->whereJsonContainsLocale('name', 'en', 'Name in English')->get();

// Returns all news items that has name in English or Dutch with value `Name in English`
NewsItem::query()->whereJsonContainsLocales('name', ['en', 'nl'], 'Name in English')->get();

// The last argument is the "operand" which you can tweak to achieve something like this:

// Returns all news items that has name in English with value like `Name in...`
NewsItem::query()->whereJsonContainsLocale('name', 'en', 'Name in%', 'like')->get();

// Returns all news items that has name in English or Dutch with value like `Name in...`
NewsItem::query()->whereJsonContainsLocales('name', ['en', 'nl'], 'Name in%', 'like')->get();
```

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/dc59c5caa4e0e03d95783ab3096e0e8922969e759f2e4cc017f11e5c825074b7/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d7472616e736c617461626c652e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-translatable)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Documentation
-------------

[](#documentation)

All documentation is available [on our documentation site](https://spatie.be/docs/laravel-translatable).

Testing
-------

[](#testing)

```
composer test
```

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

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you've found a bug regarding security please mail  instead of using the issue tracker.

Postcardware
------------

[](#postcardware)

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [Sebastian De Deyne](https://github.com/sebastiandedeyne)
- [All Contributors](../../contributors)

We got the idea to store translations as json in a column from [Mohamed Said](https://github.com/themsaid). Parts of the readme of [his multilingual package](https://github.com/themsaid/laravel-multilingual) were used in this readme.

Alternatives
------------

[](#alternatives)

- [DB-Fields-Translations](https://github.com/Afzaal565/DB-Fields-Translations)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

82

—

ExcellentBetter than 100% of packages

Maintenance90

Actively maintained with recent releases

Popularity77

Solid adoption and visibility

Community55

Growing community involvement

Maturity94

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 59.8% 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 ~45 days

Recently: every ~96 days

Total

80

Last Release

87d ago

Major Versions

1.3.0 → 2.0.02017-08-30

2.2.1 → 3.0.02018-10-16

3.1.3 → 4.0.02019-02-27

4.6.0 → 5.0.02021-03-26

v5.x-dev → 6.0.02022-03-07

PHP version history (6 changes)0.0.1PHP ^7.0

3.0.0PHP ^7.1

4.1.0PHP ^7.2

4.6.0PHP ^7.2|^8.0

5.0.0PHP ^8.0

6.12.0PHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (225 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (20 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (14 commits)")[![thaqebon](https://avatars.githubusercontent.com/u/29402142?v=4)](https://github.com/thaqebon "thaqebon (12 commits)")[![alipadron](https://avatars.githubusercontent.com/u/34191509?v=4)](https://github.com/alipadron "alipadron (11 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (10 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (8 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (7 commits)")[![patinthehat](https://avatars.githubusercontent.com/u/5508707?v=4)](https://github.com/patinthehat "patinthehat (6 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (5 commits)")[![gdebrauwer](https://avatars.githubusercontent.com/u/22586858?v=4)](https://github.com/gdebrauwer "gdebrauwer (5 commits)")[![bram-pkg](https://avatars.githubusercontent.com/u/13304739?v=4)](https://github.com/bram-pkg "bram-pkg (5 commits)")[![ahmetbarut](https://avatars.githubusercontent.com/u/36641723?v=4)](https://github.com/ahmetbarut "ahmetbarut (5 commits)")[![dont-know-php](https://avatars.githubusercontent.com/u/43349348?v=4)](https://github.com/dont-know-php "dont-know-php (5 commits)")[![yoeriboven](https://avatars.githubusercontent.com/u/4047804?v=4)](https://github.com/yoeriboven "yoeriboven (3 commits)")[![jimirobaer](https://avatars.githubusercontent.com/u/8984769?v=4)](https://github.com/jimirobaer "jimirobaer (3 commits)")[![rcerljenko](https://avatars.githubusercontent.com/u/16762056?v=4)](https://github.com/rcerljenko "rcerljenko (3 commits)")[![vencelkatai](https://avatars.githubusercontent.com/u/60509037?v=4)](https://github.com/vencelkatai "vencelkatai (3 commits)")[![mstaack](https://avatars.githubusercontent.com/u/10169509?v=4)](https://github.com/mstaack "mstaack (2 commits)")[![Muetze42](https://avatars.githubusercontent.com/u/26193232?v=4)](https://github.com/Muetze42 "Muetze42 (2 commits)")

---

Tags

eloquenti18nlaravelphptranslated-attributesspatietranslatemodeleloquentmultilinguallaravel-translatablei8n

###  Code Quality

TestsPest

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[dyrynda/laravel-model-uuid

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

4802.8M8](/packages/dyrynda-laravel-model-uuid)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)[jerome/filterable

Streamline dynamic Eloquent query filtering with seamless API request integration and advanced caching strategies.

19226.1k](/packages/jerome-filterable)

PHPackages © 2026

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