Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Translatable Laravel Package

spatie/laravel-translatable

Add multilingual fields to Eloquent models using a simple HasTranslations trait. Store translations as JSON on the model (no extra tables). Set/get translations per locale, switch app locale, fetch all translations, and even translate nested JSON keys via -> notation.

View on GitHub
Deep Wiki
Context7

title: Usage with factories weight: 1

A small helper for making translations has been added for use in factories:

This is what a few possible usages look like:

/** [@var](https://github.com/var) $this \Illuminate\Database\Eloquent\Factories\Factory */

$this->translations('en', 'english')
// output: ['en' => 'english']

$this->translations(['en', 'nl'], 'english')
// output: ['en' => 'english', 'nl' => 'english']

$this->translations(['en', 'nl'], ['english', 'dutch'])
// output: ['en' => 'english', 'nl' => 'dutch']

The helper can also be used outside of factories using the following syntax:

\Illuminate\Database\Eloquent\Factories\Factory::translations('en', 'english');
// output: ['en' => 'english']

In a Factory

class UserFactory extends \Illuminate\Database\Eloquent\Factories\Factory {
    public function definition(): array
    {
        return [
            'bio' => $this->translations('en', 'english'),
        ];
    }
}
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport