by Devin Yang
(This article was automatically translated.)

Published - 7 years ago ( Updated - 7 years ago )

In Laravel, how to use ModelFactory to create Chinese fake data?
I did this for reference.
define(AppUser::class, function (FakerGenerator $faker) {
static $password;
$tw_faker = TwFacker::create('zh_TW');
return [
'name' => $tw_faker->name,
'address' => $tw_faker->address,
'city' => preg_replace('#(.{3})(.*)#um', '$1', $tw_faker->city),
'email' => $faker->unique()->safeEmail,
'password' => $password ?: $password = bcrypt('secret'),
'remember_token' => str_random(10),
];
});

Customize a TwFacker alias, we can use him.
Here, $tw_faker->name is used to replace the original $faker->name provided by $faker->name , so the Chinese name can be stored.

We can also adjust relevant localized files in vendor/fzaninotto/faker/src/Faker/Provider/zh_TW in Laravel's special security directory.

For example, the text of Text.php can generate fake data Chinese that is more in line with our needs..
https://github.com/fzaninotto/Faker/blob/master/src/Faker/Provider/zh_TW/Text.php

Tags: laravel ModelFactory

Devin Yang

Feel free to ask me, if you don't get it.:)

No Comment

Post your comment

Login is required to leave comments

Similar Stories


dlaravel

Ha, I successfully made D-Larave run in the Raspberry Pi ARM environment

I bought the Raspberry Pi this time because I thought it was very fun. In addition, the Mac environment in my home is too new to compile Line Simple Beacon normally. Through the Raspberry Pi, it is easy to use, and there will be no problems in the environment. Of course, there are more applications. But as the author of D-Laravel, of course I have to come and give it a try.....

laravel

Introduced by @dump, new features in Laravel 5.6.8

In the directive of Laravel 5.6, there is a new function called @dump Let's see how cool he is.

dlaravel

Description of .env.example file on D-Laravel

This article explains about the .env settings on D-Laravel MYSQL_ROOT_PASSWORD=secret LARAVEL_INSTALLER='container' DOCKER_SERVICES='docker-compose.yml service/redis.yml'