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

How to set the external network IP to the Project on D-Laravel?

This video introduces how we assign Public Ip (public IP) to a specific Project in the D-Laravel environment. Whether it is the setting of the external production environment or the demo of your own project on the intranet, you can refer to the setting method of this video. In the video, although I used the external network IP of PPPoE dial-up to illustrate, we can also use the local network IP on our own computer if we change it. In this way, colleagues can connect to our D-Laravel Project.

laravel

Let's run Laravel

If you haven't heard of D-Laravel, let me introduce it. D-Laravel is a Laravel and docker execution environment built with docker-compose. Let us quickly generate Laravel projects through simple bash. This article teaches you how to use the docker image provided by D-Laravel to build a swoole execution development environment. After reading this article, you should be able to quickly create a swoole execution environment through D-Laravel.

php,docker,dlaravel

A brief introduction to the phpenv container environment I built

I don't have time to shoot an introduction video, so I'll just grab some pictures and introduce the container environment deviny/phpenv I use. https://github.com/DevinY/phpenvphpenv can be regarded as an evolutionary version of my previous D-Laravel open source project, conceptually extending the use of many Dlaravel operation methods. The update of the container tends to be controlled by the user to build his own image, so I am not very good at changing the version number. In fact, the php version number of D-Laravel seems to have not been changed for a long time:p