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

Adds HasTranslations to Eloquent models to store translations in JSON columns—no extra tables. Define translatable attributes via PHP 8 attribute or $translatable property, then set/get per-locale values while model accessors return the current app locale.

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.
codraw/entity-migrator
codraw/doctrine-extra
codraw/aws-tool-kit
codraw/validator
codraw/workflow
codraw/open-api
codraw/cron-job
codraw/process
codraw/log
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony