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


laravel storage,sftp

Use tinker to test Laravel's sftp custom Storage::path and Storage::url

Today, I will test the use of sftp driver on Laravel. If you have never used it, come and see the results of my test. By the way, it is very convenient for us to perform Storage functions in the tinker environment of Laravel, whether it is local or remote. After adjusting the settings, remember to leave and enter again.

docker,laravel

[D-Laravel]./console node

When developing Laravel, sometimes we need to install nodejs packages through npm, but Node in our system is not new enough. It may be impossible to upgrade due to some factors, such as running an old version of nodejs program, etc. In fact, we can use docker through simple commands, so that we can use the latest version of node image to mount the /sites folder on the host side. In this way, we can execute the new version of the npm command at any time.

dlaravel,docker

D-Laravel learning three stages

Chat about the three stages of using D-Laravel, why use D-Laravel. Because the configuration files used by D-Laravel are quite simple, it is very suitable for beginners of Docker to learn, And users who do not know how to use Docker can also use the two commands ./console and ./create to create a project.