当前位置:网站首页>[laravel] detailed explanation of faker data filling
[laravel] detailed explanation of faker data filling
2022-07-01 10:14:00 【Excellent Lei Shao】
install
stay laravel Has been automatically integrated in , No need to install it by hand . For use elsewhere , You can use the following command to install .
composer require fzaninotto/faker
by Faker Specify Chinese support
May pass through config/app.php Add the following configuration to support Chinese :
'faker_locale' => 'zh_CN',
Basic usage
Formatters formatter
Faker\Provider\Base basic
$randomDigit = $faker->randomDigit;// Generate 0-9 Random number between
$randomDigitNotNull = $faker->randomDigitNotNull;// Generate 1-9 Random number between
$randomNumber = $faker->randomNumber(5, true);// Generate 5 An integer ,true It means strict mode , That is only 5 position
$randomFloat = $faker->randomFloat(2, 0, 10);// Generate floating point number , Two decimal places , The scope is 0-10 Between
$numberBetween = $faker->numberBetween(0, 100);// Generate random integer , The scope is 0-100 Between
$randomLetter = $faker->randomLetter;// return a-z Any lowercase character between
$randomElements = $faker->randomElements(['a', 'b', 'c', 'd'], 2);// Returns two random elements in an array
$randomElement = $faker->randomElement(['aa', 'bb', 'cc', 'dd']);// Returns an element of an array at random
$suffle = $faker->shuffle('hello, world'); // Scramble the characters in the string and return
$suffle = $faker->shuffle(['aa', 'bb', 'cc', 'dd']); // The elements in the array are scrambled and returned
$numerify = $faker->numerify('Hello #####');//##### Replace with random numbers , The output is similar to :Hello 03501
$lexify = $faker->lexify('Hello ???');//??? Replace with 3 Random lowercase characters , The output is similar to :Hello krg
$bothify = $faker->bothify('hello ##??');//# Replace with random numbers ,? Replace with random lowercase characters . The output is similar to :hello 15cr
$asciify = $faker->asciify('hello *****');//* Replace with random characters , The output is similar to :hello 5Ynt[
$regexify = $faker->regexify('[A-Z0-9._%+-][email protected][A-Z0-9.-]+\.[A-Z]{2,4}');// Return string according to regular expression
Faker\Provider\Lorem Text
$word = $faker->word;// Return a word
$words = $faker->words(3, false);// return 3 Word ,false Indicates that an array is returned ;true Indicates that a string is returned , Words are separated by spaces
$sentence = $faker->sentence(5, true);// Return a sentence ,false Indicates that only 5 Word ,true It means that you can be in 5 About one word
$sentences = $faker->sentences(3, false);// return 3 Sentences ,false Indicates that an array is returned ,true It means to spell three sentences into one and return to
$paragraph = $faker->paragraph(3, true);// Return to a paragraph , from 3 Sentences make up .false It means that there can only be 3 Sentences ,true It means that you can be in 3 About sentences
$paragraphs = $faker->paragraphs(4, false);// return 4 Paragraphs .false Indicates that an array is returned ,true Means to splice paragraphs together , And use line breaks
$text = $faker->text(200);// Returns a piece of text , It can only contain at most 200 Characters
Faker\Provider\en_US\Person figure
$title = $faker->title('female');// Parameters :title($gender = null|'male'|'female') . Return address . for example :Mrs.|Prof.|Dr.
$titleMale = $faker->titleMale;// Returns the male address
$titleFemale = $faker->titleFemale;// Return to female address
$name = $faker->name('female');// Parameters :name($gender = null|'male'|'female') . Return name
$firstName = $faker->firstName('female');// Parameters :firstName($gender = null|'male'|'female') . Return name
$firstNameMale = $faker->firstNameMale;// Male name
$firstNameFemale = $faker->firstNameFemale;// Female name
$lastName = $faker->lastName;// surname
Faker\Provider\en_US\Address Address
$cityPrefix = $faker->cityPrefix;// City prefix . Such as :Lake
$secondaryAddress = $faker->secondaryAddress;// Secondary address . Such as :Suite 061
$state = $faker->state;// state 、 province ( Such as :Colorado、 Sichuan Province )
$stateAbbr = $faker->stateAbbr;// Province abbreviation . Such as : Jin 、 Mongolia 、 Zhejiang 、 Ji
$citySuffix = $faker->citySuffix;// City suffix . Such as :side、land、port、Ville
$streetSuffix = $faker->streetSuffix;// Street suffix . Such as :Ramp、Plains
$buildingNumber = $faker->buildingNumber;// Building number
$city = $faker->city;// City
$streetName = $faker->streetName;// Street name
$streetAddress = $faker->streetAddress;// Street address
$postcode = $faker->postcode;// Postal Code
$address = $faker->address;// Address ( City + District )
$country = $faker->country;// Country
$latitude = $faker->latitude;// latitude latitude($min = -90, $max = 90)
$longitude = $faker->longitude;// longitude longitude($min = -180, $max = 180)
Faker\Provider\en_US\PhoneNumber Phone number
$phoneNumber = $faker->phoneNumber;// Phone number
$tollFreePhoneNumber = $faker->tollFreePhoneNumber;
$e164PhoneNumber = $faker->e164PhoneNumber;
Faker\Provider\en_US\Company company
$catchPhrase = $faker->catchPhrase;// slogan
$bs = $faker->bs;
$company = $faker->company;// Corporate name
$companySuffix = $faker->companySuffix;// Company name suffix
$jobTitle = $faker->jobTitle;// The title
Faker\Provider\en_US\Text Text
$realText = $faker->realText();// A narrative text
Faker\Provider\DateTime Date time
$unixTime = $faker->unixTime;// Return random timestamp
$unixTime = $faker->unixTime('now');// Return random timestamp Optional deadline
$dateTime = $faker->dateTime;// Returns a random DateTime object
$dateTime = $faker->dateTime('now', 'PRC');// Returns a random DateTime object , You can select a deadline and time zone
$dateTimeAD = $faker->dateTimeAD;// Returns a random DateTime object
$dateTimeAD = $faker->dateTimeAD('now', 'PRC');// Returns a random DateTime object , You can select a deadline and time zone
$iso8601 = $faker->iso8601;// Returns a random string of time
$iso8601 = $faker->iso8601('now');// Returns a random string of time , You can select a deadline
$date = $faker->date("Y-m-d H:i:s", 'now');// Specify format return time , You can select a deadline
$time = $faker->time('Y-m-d H:i:s', 'now');//( ditto ) Specify format return time , You can select a deadline
$dateTimeBetween = $faker->dateTimeBetween('2019-01-01', 'now', 'PRC');// Returns DateTime object , Optional time zone
$dateTimeInInterval = $faker->dateTimeInInterval('-5 years', '+5 days', 'PRC');// Returns DateTime object , Optional time zone ( The first parameter : Starting time , The second parameter : Time range )
$dateTimeThisCentury = $faker->dateTimeThisCentury;// Return to a century DateTime object
$dateTimeThisCentury = $faker->dateTimeThisCentury('1950-01-01', 'PRC');// Return to a century DateTime object . Specify the deadline and time zone
$dateTimeThisDecade = $faker->dateTimeThisDecade;// Return to a previous decade DateTime object
$dateTimeThisDecade = $faker->dateTimeThisDecade('2015-01-01', 'PRC');// Return to a previous decade DateTime object . Specify the last time and time zone allowed
$dateTimeThisYear = $faker->dateTimeThisYear;// Return to a previous year DateTime object
$dateTimeThisYear = $faker->dateTimeThisYear('now', 'PRC');// Return to a previous year DateTime object . Specify the last time and time zone allowed
$dateTimeThisMonth = $faker->dateTimeThisMonth;// Returns a previous month DateTime object
$dateTimeThisMonth = $faker->dateTimeThisMonth('-15 days', 'PRC');// Returns a previous month DateTime object . Specify the last time and time zone allowed
$amPm = $faker->amPm;// In the morning / Afternoon
$dayOfMonth = $faker->dayOfMonth;// Return the number
$dayOfWeek = $faker->dayOfWeek;// Day of the week
$month = $faker->month;// Return to the month
$monthName = $faker->monthName;// Returns the name of the month
$year = $faker->year;// Return year
$year = $faker->year('2000-01-01');// Return year . You can specify a deadline
$timezone = $faker->timezone;// Back to the time zone
Faker\Provider\Internet Internet
$email = $faker->email;// Return a random email
$safeEmail = $faker->safeEmail;// Return one to @example.com Safe mailbox at the end
$freeEmail = $faker->freeEmail;// Return a random email
$companyEmail = $faker->companyEmail;// Return to the enterprise mailbox ( Not available under Chinese language pack )
$freeEmailDomain = $faker->freeEmailDomain;// Return a mail domain name
$safeEmailDomain = $faker->safeEmailDomain;// Return the safe mail domain name
$userName = $faker->userName;// user name
$password = $faker->password;// password
$domainName = $faker->domainName;// domain name ( Not available under Chinese language pack )
$domainWord = $faker->domainWord;// Domain name without suffix ( Not available under Chinese language pack )
$tld = $faker->tld;// The domain name suffix : Such as com、org( Not available under Chinese language pack )
$url = $faker->url;// Return a random url( Not available under Chinese language pack )
$slug = $faker->slug;
$ipv4 = $faker->ipv4;// Return to one ipv4 Address
$ipv6 = $faker->ipv6;// Return to one ipv6 Address
$localIpv4 = $faker->localIpv4;
$macAddress = $faker->macAddress;//mac Address
Faker\Provider\UserAgent The user agent
$userAgent = $faker->userAgent;// Returns a random user agent information
$chrome = $faker->chrome;// Return to one chrome User agent information of the browser
$firefox = $faker->firefox;// Return to one firefox User agent information of the browser
$safari = $faker->safari;// Return to one safari User agent information of the browser
$opera = $faker->opera;// Return to one opera User agent information of the browser
$internetExplorer = $faker->internetExplorer;// Return to one internetExplorer User agent information of the browser
Faker\Provider\Payment payment
$creditCardType = $faker->creditCardType;// Credit card type
$creditCardNumber = $faker->creditCardNumber;// Credit card number
$creditCardExpirationDate = $faker->creditCardExpirationDate;// Credit card expiration date (DateTime object )
$creditCardExpirationDateString = $faker->creditCardExpirationDateString;// Credit card expiration date string
$creditCardDetails = $faker->creditCardDetails;// Credit card details ( Array )
$swiftBicNumber = $faker->swiftBicNumber;
$iban = $faker->iban;// International bank accounts
Faker\Provider\Color Color
$hexcolor = $faker->hexcolor;// Hexadecimal random color :'#fa3cc2'
$rgbcolor = $faker->rgbcolor;//RGB Random color of the format ( String form ):'0,255,122'
$rgbColorAsArray = $faker->rgbColorAsArray;//RGB Random color of the format ( Array form ):array(0,255,122)
$rgbCssColor = $faker->rgbCssColor;//RGB Format random color css Express :'rgb(0,255,122)'
$safeColorName = $faker->safeColorName;// A safe random color name
$colorName = $faker->colorName;// Random color name
Faker\Provider\File file
$fileExtension = $faker->fileExtension;// file extension
$mimeType = $faker->mimeType;//mime type
// Copy a random file from the source file to the destination directory , And back to fullpath
$file = $faker->file($sourceDir = './up1', $targetDir = './up2');
// Copy a random file from the source file to the destination directory , And back to basename
$file = $faker->file($sourceDir = './up1', $targetDir = './up2', false);
Faker\Provider\Image picture
$imageUrl = $faker->imageUrl();//https://lorempixel.com/640/480/?93028
$imageUrl = $faker->imageUrl(320, 320, 'cats');//https://lorempixel.com/320/320/cats/?68416
$imageUrl = $faker->imageUrl(320, 320, 'cats', true, 'Faker');//https://lorempixel.com/320/320/cats/Faker/?68118
$imageUrl = $faker->imageUrl(320, 320, 'cats', true, 'Faker', true);//https://lorempixel.com/gray/320/320/cats/Faker/?28732
// Generate a picture and save it locally '/tmp/13b73edae8443990be1aa8f1a483bc27.jpg'
$image = $faker->image('./tmp', 320, 320);
// Set categories and generate pictures to save locally 'tmp/13b73edae8443990be1aa8f1a483bc27.jpg'
$image = $faker->image('./tmp', 320, 320, 'cats');
// Set categories and generate pictures to save locally , Only the file name is returned '13b73edae8443990be1aa8f1a483bc27.jpg'
$image = $faker->image('./tmp', 320, 320, 'cats', false);
// Generate images without randomization
$image = $faker->image('./tmp', 320, 320, 'cats', true, false);
// Generate image and add watermark font 'tmp/13b73edae8443990be1aa8f1a483bc27.jpg'
$image = $faker->image('./tmp', 320, 320, 'cats', true, true, 'Faker');
Faker\Provider\Uuid UUID
$uuid = $faker->uuid;// Generate a uuid
Faker\Provider\Barcode Bar code
$ean13 = $faker->ean13;//8105964964473
$ean8 = $faker->ean8;//05994441
$isbn13 = $faker->isbn13;//9780971408739
$isbn10 = $faker->isbn10;//0813387299
Faker\Provider\Miscellaneous All kinds of
$boolean = $faker->boolean;// Generate a Boolean value
$md5 = $faker->md5;// Generate a md5 code
$sha1 = $faker->sha1;// Generate a sha1
$sha256 = $faker->sha256;// Generate a sha256
$locale = $faker->locale;// Generate a region code : Such as zh_CN
$countryCode = $faker->countryCode;// Generate a country code . Such as :UK
$languageCode = $faker->languageCode;// Generate a language code . Such as :en
$currencyCode = $faker->currencyCode;// Generate a currency code . Such as :EUR
$emoji = $faker->emoji;// Generate a emoji expression
Faker\Provider\Biased Biased
// obtain 10 To 20 Random number between , And more opportunities to approach 20
$biasedNumberBetween = $faker->biasedNumberBetween($min = 10, $max = 20, $function = 'sqrt');
Faker\Provider\HtmlLorem html Text
// Generate no more than 2 Level depth HTML file , And no more than... At any level 3 Elements .
$randomHtml = $faker->randomHtml(2, 3);
Language specific formatters Language specific formatter
// Generate a random bank name ( Based on the list of real Chinese banks )
echo $faker->bank; // ' China Construction Bank '
边栏推荐
- button按钮清除边框
- What a high commission! The new programmer's partner plan is coming. Everyone can participate!
- Have you learned the necessary global exception handler for the project
- “中移链”国密引擎在BSN正式上线
- STM32逆变器电源设计方案,基于STM32F103控制器[通俗易懂]
- 好高的佣金,《新程序员》合伙人计划来袭,人人皆可参与!
- 日本教授起诉英特尔FPGA与SoC产品侵犯一项设计专利
- 【论文阅读】Trajectory-guided Control Prediction for End-to-end Autonomous Driving: A Simple yet Strong Ba
- 一个悄然崛起的国产软件,低调又强大!
- 主流实时流处理计算框架Flink初体验
猜你喜欢
预制菜迎来“黄金时代”,谁能领跑下一个万亿市场
Wechat emoticons are written into the judgment, and the OK and bomb you send may become "testimony in court"
云原生到底是什么?它会是未来发展的趋势吗?
谁还在买“三只松鼠”们
Dotnet console uses microsoft Maui. Getting started with graphics and skia
Japanese professor sues Intel FPGA and SOC products for infringing a design patent
Meituan P4 carefully collated microservice system architecture design manual to see the world of microservice architecture
Venv: directory structure of venv
历史上的今天:九十年代末的半导体大战;冯·诺依曼发表第一份草案;CBS 收购 CNET...
The stock position building rate of global funds and asset management reached a new low in 15 years
随机推荐
“中移链”国密引擎在BSN正式上线
这样理解mmap,挺有意思!
请问有没有人知道clickhouse 中 limit语句执行的逻辑,图片中,上面的SQL可以执行成功
CodeBlocks 左侧项目栏消失,workspace 自动保存项目,Default workspace,打开上次的workspace,工作区(图文教程,已解决)
主流实时流处理计算框架Flink初体验
In the new database era, don't just learn Oracle and MySQL
CentOS configures discuz prompt, please check whether the MySQL module is loaded correctly
PO模式深入封装
历史上的今天:九十年代末的半导体大战;冯·诺依曼发表第一份草案;CBS 收购 CNET...
I like two men...
Module 9: design e-commerce seckill system
button按钮清除边框
谁还在买“三只松鼠”们
mysql cdc能把能把op字段拿出来吗
A quietly rising domestic software, low-key and powerful!
The stock position building rate of global funds and asset management reached a new low in 15 years
7-Zip 遭抵制?呼吁者定下“三宗罪”:伪开源、不安全、作者来自俄罗斯!
Postgraduate entrance examination vocabulary 2023 sharing (1)
Ubuntu系统安装与配置MySQL
Who's still buying three squirrels