---
title: "Translatable models — Translatable for Laravel | Roundly"
description: "Add the HasTranslations trait and the Translatable contract, list attributes in $translatable, and optionally override fallback per model."
url: https://roundly-consulting.com/open-source/docs/translatable-for-laravel/models
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Translatable for Laravel](https://roundly-consulting.com/open-source/docs/translatable-for-laravel.md)

# Translatable models

List the translatable attributes in a public array $translatable property and implement the Translatable contract — the HasTranslations trait provides every method. The model needs no array cast: the trait owns JSON serialization for its listed attributes.

```php
use Illuminate\Database\Eloquent\Model;
use RoundlyConsulting\Translatable\Concerns\HasTranslations;
use RoundlyConsulting\Translatable\Contracts\Translatable;

final class Topic extends Model implements Translatable
{
    use HasTranslations;

    protected $fillable = ['name', 'description'];

    /** @var list<string> */
    public array $translatable = ['name', 'description'];
}
```

- Implement the contract. Translatable is what Translatable::apply() and the Blade component type-hint against, and it extends sluggable’s ProvidesLocaleMaps — a model without it can’t get per-locale slugs.
- Don’t add a cast for listed attributes — the trait reads and writes the raw JSON itself.
- Mass assignment works as usual: add the attributes to $fillable (or use $guarded) and pass locale maps, e.g. Topic::create(\['name' => \['en' => 'Investing'\]\]).
- Calling any translation method or scope with an attribute that isn’t listed throws NotATranslatableAttributeException.

## Per-model fallback

Override the global fallback mode and fallback locale on a single model with two optional protected properties:

```php
use RoundlyConsulting\Translatable\Enums\FallbackMode;

protected ?FallbackMode $translatableFallbackMode = FallbackMode::Fallback;
protected ?string $translatableFallbackLocale = 'en';
```

When a property is null, absent or a typed property left uninitialised, the config value applies. The mode also accepts its string value (protected $translatableFallbackMode = 'none';); a value that names no mode throws the toolkit’s InvalidConfigurationException instead of silently using the global mode. The fallback locale is validated like the config setting — a malformed key throws InvalidLocaleException, blank means no fallback locale. See Fallback modes for what each mode does.

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/translatable-for-laravel.md)
