Laravel faker multiple languages

Yish
Yish
Feb 25, 2019 · 1 min read

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

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store