当前位置:网站首页>[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 '边栏推荐
- Centos 配置discuz 提示请检查 mysql 模块是否正确加载
- 新数据库时代,不要只学 Oracle、MySQL
- 哪个券商公司炒股开户佣金低又安全又可靠
- Ssh server rejects password, try again; Permitrootlogin yes invalid problem
- 零基础入行软件测试必看,10年测试老鸟的良心建议(共15条)
- Apple amplification! It's done so well
- 编写自己的who命令
- Continue to advance, and softcom power steadily promotes cloud intelligence strategy
- PHP 字符串与二进制相互转换
- JD and Tencent renewed the three-year strategic cooperation agreement; The starting salary rose to 260000 yuan! Samsung sk of South Korea competes for salary increase to retain semiconductor talents;
猜你喜欢

零基础入门测试该学什么?最全整理,照着学就对了

关于#SQL#的问题,如何解决?

CodeBlocks 左侧项目栏消失,workspace 自动保存项目,Default workspace,打开上次的workspace,工作区(图文教程,已解决)

A quietly rising domestic software, low-key and powerful!

If you meet a female driver and drive didi as an amateur, you can earn 500 a day!
![C [byte array] and [hexadecimal string] mutual conversion - codeplus series](/img/d2/dad88f53701c7cd7638bd4983cbb4b.png)
C [byte array] and [hexadecimal string] mutual conversion - codeplus series

C# 一行代码计算文件的MD5值 - CodePlus系列

Venv: directory structure of venv

Strange, why is the ArrayList initialization capacity size 10?

IDEA运行报错Command line is too long. Shorten command line for...
随机推荐
I like two men...
零基础入门测试该学什么?最全整理,照着学就对了
It is interesting to understand MMAP in this way!
好高的佣金,《新程序员》合伙人计划来袭,人人皆可参与!
Daily mathematics serial 55: February 24
年薪100万,在北上广深买的起房子吗?
项目必用的全局异常处理器,你学会了吗
SQL Server列一相同的情况下,如何取列二的最大值,并重新生成表
建议收藏 | 在openGauss上遇到慢SQL该怎么办?
CodeBlocks 左侧项目栏消失,workspace 自动保存项目,Default workspace,打开上次的workspace,工作区(图文教程,已解决)
tryhackme圣诞挑战2021-Advent of Cyber 3-day1-IDOR漏洞,不安全的访问控制漏洞
C one line code calculates the MD5 value of the file - codeplus series
Meituan P4 carefully collated microservice system architecture design manual to see the world of microservice architecture
Today in history: the semiconductor war in the late 1990s; Von Neumann published the first draft; CBS acquires CNET
树莓派4B系统搭建(超详细版)
微信表情符号写入判决书,你发的OK、炸弹都可能成为“呈堂证供”
新数据库时代,不要只学 Oracle、MySQL
Apple amplification! It's done so well
JD and Tencent renewed the three-year strategic cooperation agreement; The starting salary rose to 260000 yuan! Samsung sk of South Korea competes for salary increase to retain semiconductor talents;
Venv: directory structure of venv