spatie / laravel-translatable

Making Eloquent models translatable

Home Page:https://spatie.be/docs/laravel-translatable

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to write a factory that populate a post description with multi-language content?

davide-casiraghi opened this issue · comments

I'm trying to create a Factory to populate a Post with dummy data.
In this Post model, the description can be translated into English and Italian.
But I can't find in the documentation how to write a Factory that addresses this task.

Is it possible to do that?

This is the code of the definition function of my factory at the moment.

public function definition()
    {
        return [
            'name' => $this->faker->sentence($nbWords = 2, $variableNbWords = true),
            'description' => $this->faker->paragraph($nbSentences = 2, $variableNbSentences = true),
        ];
    }
public function definition() {
    return [
        'name' => $this->faker->sentence($nbWords = 2, $variableNbWords = true),
        'description' => [
                'en' => $this->faker->paragraph($nbSentences = 2, $variableNbSentences = true),
                'it' => $this->faker->paragraph($nbSentences = 2, $variableNbSentences = true),
        ],
    ];
}

Thank you! It works like a charm.