laravel批量生成假數(shù)據(jù)的方法
D:\phpStudy\WWW\api.douxiaoli.com\database\factories\ModelFactory.php D:\phpStudy\WWW\BCCKidV1.0\vendor\fzaninotto\faker\src\Faker\Generator.php
$factory->define(App\User::class, function (Faker\Generator $faker) { static $password; #定義假數(shù)據(jù)長(zhǎng)什么樣子 return [ 'name' => $faker->name, 'email' => $faker->unique()->safeEmail, 'password' => $password ?: $password = bcrypt('test12345'), 'api_token' => str_random(60), 'remember_token' => str_random(10), ]; });
然后在命令行中運(yùn)行:
php artisan thinker factory(‘App\User',10)->create();
這個(gè)地方的引號(hào)是英文的,csdn編輯器原因,復(fù)制出來之后是中文的,記得改成英文。
那個(gè)10表示一次生成10個(gè)假數(shù)據(jù)。
數(shù)據(jù)庫結(jié)果記錄:
其他可用的東東:
/** * @property string $name * @method string name(string $gender = null) * @property string $firstName * @method string firstName(string $gender = null) * @property string $firstNameMale * @property string $firstNameFemale * @property string $lastName * @property string $title * @method string title(string $gender = null) * @property string $titleMale * @property string $titleFemale * * @property string $citySuffix * @property string $streetSuffix * @property string $buildingNumber * @property string $city * @property string $streetName * @property string $streetAddress * @property string $postcode * @property string $address * @property string $country * @property float $latitude * @property float $longitude * * @property string $ean13 * @property string $ean8 * @property string $isbn13 * @property string $isbn10 * * @property string $phoneNumber * * @property string $company * @property string $companySuffix * @property string $jobTitle * * @property string $creditCardType * @property string $creditCardNumber * @method string creditCardNumber($type = null, $formatted = false, $separator = '-') * @property \DateTime $creditCardExpirationDate * @property string $creditCardExpirationDateString * @property array $creditCardDetails * @property string $bankAccountNumber * @method string iban($countryCode = null, $prefix = '', $length = null) * @property string $swiftBicNumber * @property string $vat * * @property string $word * @property string|array $words * @method string|array words($nb = 3, $asText = false) * @property string $sentence * @method string sentence($nbWords = 6, $variableNbWords = true) * @property string|array $sentences * @method string|array sentences($nb = 3, $asText = false) * @property string $paragraph * @method string paragraph($nbSentences = 3, $variableNbSentences = true) * @property string|array $paragraphs * @method string|array paragraphs($nb = 3, $asText = false) * @property string $text * @method string text($maxNbChars = 200) * * @method string realText($maxNbChars = 200, $indexSize = 2) * * @property string $email * @property string $safeEmail * @property string $freeEmail * @property string $companyEmail * @property string $freeEmailDomain * @property string $safeEmailDomain * @property string $userName * @property string $password * @method string password($minLength = 6, $maxLength = 20) * @property string $domainName * @property string $domainWord * @property string $tld * @property string $url * @property string $slug * @method string slug($nbWords = 6, $variableNbWords = true) * @property string $ipv4 * @property string $ipv6 * @property string $localIpv4 * @property string $macAddress * * @property int $unixTime * @property \DateTime $dateTime * @property \DateTime $dateTimeAD * @property string $iso8601 * @property \DateTime $dateTimeThisCentury * @property \DateTime $dateTimeThisDecade * @property \DateTime $dateTimeThisYear * @property \DateTime $dateTimeThisMonth * @property string $amPm * @property int $dayOfMonth * @property int $dayOfWeek * @property int $month * @property string $monthName * @property int $year * @property int $century * @property string $timezone * @method string amPm($max = 'now') * @method string date($format = 'Y-m-d', $max = 'now') * @method string dayOfMonth($max = 'now') * @method string dayOfWeek($max = 'now') * @method string iso8601($max = 'now') * @method string month($max = 'now') * @method string monthName($max = 'now') * @method string time($format = 'H:i:s', $max = 'now') * @method string unixTime($max = 'now') * @method string year($max = 'now') * @method \DateTime dateTime($max = 'now', $timezone = null) * @method \DateTime dateTimeAd($max = 'now', $timezone = null) * @method \DateTime dateTimeBetween($startDate = '-30 years', $endDate = 'now') * @method \DateTime dateTimeInInterval($date = '-30 years', $interval = '+5 days', $timezone = null) * @method \DateTime dateTimeThisCentury($max = 'now', $timezone = null) * @method \DateTime dateTimeThisDecade($max = 'now', $timezone = null) * @method \DateTime dateTimeThisYear($max = 'now', $timezone = null) * @method \DateTime dateTimeThisMonth($max = 'now', $timezone = null) * * @property string $md5 * @property string $sha1 * @property string $sha256 * @property string $locale * @property string $countryCode * @property string $countryISOAlpha3 * @property string $languageCode * @property string $currencyCode * @property boolean $boolean * @method boolean boolean($chanceOfGettingTrue = 50) * * @property int $randomDigit * @property int $randomDigitNotNull * @property string $randomLetter * @property string $randomAscii * @method int randomNumber($nbDigits = null, $strict = false) * @method int|string|null randomKey(array $array = array()) * @method int numberBetween($min = 0, $max = 2147483647) * @method float randomFloat($nbMaxDecimals = null, $min = 0, $max = null) * @method mixed randomElement(array $array = array('a', 'b', 'c')) * @method array randomElements(array $array = array('a', 'b', 'c'), $count = 1, $allowDuplicates = false) * @method array|string shuffle($arg = '') * @method array shuffleArray(array $array = array()) * @method string shuffleString($string = '', $encoding = 'UTF-8') * @method string numerify($string = '###') * @method string lexify($string = '????') * @method string bothify($string = '## ??') * @method string asciify($string = '****') * @method string regexify($regex = '') * @method string toLower($string = '') * @method string toUpper($string = '') * @method Generator optional($weight = 0.5, $default = null) * @method Generator unique($reset = false, $maxRetries = 10000) * @method Generator valid($validator = null, $maxRetries = 10000) * * @method integer biasedNumberBetween($min = 0, $max = 100, $function = 'sqrt') * * @property string $macProcessor * @property string $linuxProcessor * @property string $userAgent * @property string $chrome * @property string $firefox * @property string $safari * @property string $opera * @property string $internetExplorer * @property string $windowsPlatformToken * @property string $macPlatformToken * @property string $linuxPlatformToken * * @property string $uuid * * @property string $mimeType * @property string $fileExtension * @method string file($sourceDirectory = '/tmp', $targetDirectory = '/tmp', $fullPath = true) * * @method string imageUrl($width = 640, $height = 480, $category = null, $randomize = true, $word = null, $gray = false) * @method string image($dir = null, $width = 640, $height = 480, $category = null, $fullPath = true, $randomize = true, $word = null) * * @property string $hexColor * @property string $safeHexColor * @property string $rgbColor * @property array $rgbColorAsArray * @property string $rgbCssColor * @property string $safeColorName * @property string $colorName * * @method string randomHtml($maxDepth = 4, $maxWidth = 4) * */
以上這篇laravel批量生成假數(shù)據(jù)的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- Laravel 批量更新多條數(shù)據(jù)的示例
- laravel實(shí)現(xiàn)批量更新多條記錄的方法示例
- Laravel中批量賦值Mass-Assignment的真正含義詳解
- Laravel框架學(xué)習(xí)筆記之批量更新數(shù)據(jù)功能
- Laravel框架實(shí)現(xiàn)的批量刪除功能示例
- Laravel向公共模板賦值方法總結(jié)
- Laravel 實(shí)現(xiàn)Controller向blade前臺(tái)模板賦值的四種方式小結(jié)
- Laravel5.1數(shù)據(jù)庫連接、創(chuàng)建數(shù)據(jù)庫、創(chuàng)建model及創(chuàng)建控制器的方法
- Laravel5.1框架注冊(cè)中間件的三種場(chǎng)景詳解
- laravel5.1框架model類查詢的實(shí)現(xiàn)方法
- laravel5.1框架下的批量賦值實(shí)現(xiàn)方法分析
相關(guān)文章
PHP 獲取視頻時(shí)長(zhǎng)的實(shí)例代碼
本文通過實(shí)例代碼給大家介紹了php獲取視頻時(shí)長(zhǎng)的相關(guān)知識(shí),非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2018-07-07ThinkPHP快速入門實(shí)例教程之?dāng)?shù)據(jù)分頁
這篇文章主要介紹了ThinkPHP快速入門實(shí)例教程的數(shù)據(jù)分頁實(shí)現(xiàn)過程,需要的朋友可以參考下2014-07-07PHP設(shè)計(jì)模式(七)組合模式Composite實(shí)例詳解【結(jié)構(gòu)型】
這篇文章主要介紹了PHP設(shè)計(jì)模式:組合模式Composite,結(jié)合實(shí)例形式詳細(xì)分析了PHP組合模式Composite基本概念、功能、原理、用法及操作注意事項(xiàng),需要的朋友可以參考下2020-05-05php上傳apk后自動(dòng)提取apk包信息的使用(示例下載)
本篇文章介紹了,php上傳apk后自動(dòng)提取apk包信息的使用(示例下載)需要的朋友參考下2013-04-04使用新浪微博API的OAuth認(rèn)證發(fā)布微博實(shí)例
這篇文章主要介紹了使用新浪微博API的OAuth認(rèn)證發(fā)布微博實(shí)例的相關(guān)資料,需要的朋友可以參考下2015-03-03ThinkPHP調(diào)用百度翻譯類實(shí)現(xiàn)在線翻譯
這篇文章主要介紹了ThinkPHP調(diào)用百度翻譯類實(shí)現(xiàn)在線翻譯,需要的朋友可以參考下2014-06-06Yii2 GridView實(shí)現(xiàn)列表頁直接修改數(shù)據(jù)的方法
這篇文章主要介紹了Yii2 GridView實(shí)現(xiàn)列表頁直接修改數(shù)據(jù)的方法的相關(guān)資料,小編認(rèn)為非常具有參考價(jià)值,特此分享到腳本之家平臺(tái),需要的朋友可以參考下2016-05-05Zend Framework教程之模型Model基本規(guī)則和使用方法
這篇文章主要介紹了Zend Framework教程之模型Model基本規(guī)則和使用方法,結(jié)合實(shí)例形式詳細(xì)分析了Zend Framework中模型的原理與具體使用技巧,需要的朋友可以參考下2016-03-03Swoole?webSocket消息服務(wù)系統(tǒng)壓力測(cè)試解析
這篇文章主要為大家介紹了Swoole?webSocket消息服務(wù)系統(tǒng)壓力測(cè)試解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03