当前位置:网站首页>[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 '边栏推荐
- Fried money, lost 10million.
- 7-Zip boycotted? The callers have committed "three crimes": pseudo open source, unsafe, and the author is from Russia!
- 程序员都想去国企?技术落后薪资低,躺平几年出来都找不到工作...
- Hardware midrange project
- [fxcg] large scale job hopping may be one of the driving forces behind the soaring inflation in the United States
- About widthstep of images in opencv
- 哪个券商公司炒股开户佣金低又安全又可靠
- Can MySQL CDC take out the op field
- PHP string to binary conversion
- Who has the vision to cross the cycle?
猜你喜欢

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

Live broadcast management project

京东与腾讯续签三年战略合作协议;起薪涨至26万元!韩国三星SK争相加薪留住半导体人才;Firefox 102 发布|极客头条...

leetcode:111. Minimum depth of binary tree

Kotlin 协程调度切换线程是时候解开真相了

持续进阶,软通动力稳步推动云智能战略

年薪100万,在北上广深买的起房子吗?

直播管理项目

Venv: directory structure of venv

Finally, someone made it clear what DRAM and NAND flash are
随机推荐
SQL Server列一相同的情况下,如何取列二的最大值,并重新生成表
硬件中台项目
CSDN一站式云服务开放内测,诚邀新老用户来抢鲜
Tryhackme Christmas challenge 2021 advance of cyber 3-day1-idor vulnerability, insecure access control vulnerability
High precision factorial
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;
【黑马早报】俞敏洪称从来不看新东方股价;恒驰5将于7月开启预售;奈雪虚拟股票或涉嫌非法集资;7月1日起冰墩墩停产...
Ubuntu system installation and MySQL configuration
Scratch big fish eat small fish Electronic Society graphical programming scratch grade examination level 2 true questions and answers analysis June 2022
About widthstep of images in opencv
Eat a rich woman's melon...
The programmer was beaten.
机器学习之线性回归详解
A quietly rising domestic software, low-key and powerful!
Packetdrill script analysis guide
Precautions for lvgl v8.2 string display on keil MDK (take little bear pie as an example)
Initial experience of Flink, a mainstream real-time stream processing computing framework
PHP code audit and File Inclusion Vulnerability
Project procurement management
Today in history: the semiconductor war in the late 1990s; Von Neumann published the first draft; CBS acquires CNET