当前位置:网站首页>[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 '边栏推荐
- This is the best flash popular science article I have ever seen!
- Precautions for lvgl v8.2 string display on keil MDK (take little bear pie as an example)
- 这样理解mmap,挺有意思!
- Is the securities account opened by Yixue school for individuals safe? Is there a routine
- button按钮清除边框
- IDEA运行报错Command line is too long. Shorten command line for...
- 关于#数据库#的问题:GBase 8s中如何避免死锁
- The programmer was beaten.
- Ubuntu system installation and MySQL configuration
- Wechat emoticons are written into the judgment, and the OK and bomb you send may become "testimony in court"
猜你喜欢

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

12.Gateway新一代网关

7-Zip boycotted? The callers have committed "three crimes": pseudo open source, unsafe, and the author is from Russia!

项目必用的全局异常处理器,你学会了吗

Sleeping second brother...

Continue to advance, and softcom power steadily promotes cloud intelligence strategy

Today in history: the semiconductor war in the late 1990s; Von Neumann published the first draft; CBS acquires CNET

Wechat emoticons are written into the judgment, and the OK and bomb you send may become "testimony in court"

Apple amplification! It's done so well

What is cloud primordial? Will it be the trend of future development?
随机推荐
Graduation summary of actual combat camp
The programmer was beaten.
哪个券商公司炒股开户佣金低又安全又可靠
Does anyone know the logic of limit statement execution in Clickhouse? In the picture, the SQL above can be executed successfully
MySQL common commands
How to understand JS promise
BSN long story 10: how to ensure the safety of NFT
年薪100万,在北上广深买的起房子吗?
The latest masterpiece of Alibaba, which took 182 days to produce 1015 pages of distributed full stack manual, is so delicious
【Laravel 】faker数据填充详解
MySQL interception_ MySQL method for intercepting strings [easy to understand]
程序员都想去国企?技术落后薪资低,躺平几年出来都找不到工作...
STM32 inverter power supply design scheme, based on STM32F103 controller [easy to understand]
In the new database era, don't just learn Oracle and MySQL
Zero foundation software testing must see, 10 years of testing old bird's conscience suggestions (a total of 15)
硬件中台项目
新数据库时代,不要只学 Oracle、MySQL
好高的佣金,《新程序员》合伙人计划来袭,人人皆可参与!
[dark horse morning post] Yu Minhong said he never looked at the stock price of New Oriental; Hengchi 5 will start pre-sale in July; Naixue virtual stock or suspected of illegal fund-raising; From Jul
大佬们 有没有搞过sink分流写入clickhouse 或者其他数据库的操作。