NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages
Translatable for Laravel

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.

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

final class Topic extends Model implements Translatable
{
    use HasTranslations;

    /** @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:

use RoundlyConsulting\Translatable\Enums\FallbackMode;

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

When a property is null or absent, the config value applies. 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

By donating, you agree to our donation terms.

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.