/Laravel

Laravel faker multiple languages

When you make your fake data you maybe consider using model factory to generate, but sometimes you need to set multiple languages for each columns.


You can set language for all faker, it’s means global settings. The setting is in app.php

'faker_locale' => 'en_US',

Documentation

Next, in my case I need to set multiple languages for each column, for example, address field I need to set Koran, also name field I need to set Chinese.

You can use addProvider to assign specific column translation.

$factory->define(App\Customer::class, function (Faker $faker) {
    $faker->addProvider(new \Faker\Provider\zh_TW\Person($faker));
    $faker->addProvider(new \Faker\Provider\ko_KR\Address($faker));

    return [
        'name' => $faker->name, // 張大明
        'address' => $faker->address, // 광주광역시 종로구 선릉로 9843
    ];
});

Faker repository

Yish

Yish

The creator of yish.dev

Read More