gpt4 book ai didi

laravel批量生成假数据的方法

转载 作者:qq735679552 更新时间:2022-09-29 22:32:09 25 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章laravel批量生成假数据的方法由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

?
1
2
D:\phpStudy\WWW\api.douxiaoli.com\database\factories\ModelFactory.php
D:\phpStudy\WWW\BCCKidV1.0\vendor\fzaninotto\faker\src\Faker\Generator.php
?
1
2
3
4
5
6
7
8
9
10
11
$factory ->define(App\User:: class , function (Faker\Generator $faker ) {
  static $password ;
  #定义假数据长什么样子
  return [
   'name' => $faker ->name,
   'email' => $faker ->unique()->safeEmail,
   'password' => $password ?: $password = bcrypt( 'test12345' ),
   'api_token' => str_random(60),
   'remember_token' => str_random(10),
  ];
});

然后在命令行中运行:

?
1
2
php artisan thinker
factory(‘App\User',10)->create();

这个地方的引号是英文的,csdn编辑器原因,复制出来之后是中文的,记得改成英文.

那个10表示一次生成10个假数据.

laravel批量生成假数据的方法

数据库结果记录:

laravel批量生成假数据的方法

其他可用的东东:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/**
  * @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批量生成假数据的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我.

原文链接:https://blog.csdn.net/zhezhebie/article/details/78153265 。

最后此篇关于laravel批量生成假数据的方法的文章就讲到这里了,如果你想了解更多关于laravel批量生成假数据的方法的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com