laravel批量生成假数据的方法


Posted in PHP onOctober 09, 2019
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;
 #定义假数据长什么样子
 return [
  'name' => $faker->name,
  'email' => $faker->unique()->safeEmail,
  'password' => $password ?: $password = bcrypt('test12345'),
  'api_token' => str_random(60),
  'remember_token' => str_random(10),
 ];
});

然后在命令行中运行:

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

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

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

laravel批量生成假数据的方法

数据库结果记录:

laravel批量生成假数据的方法

其他可用的东东:

/**
 * @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批量生成假数据的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

PHP 相关文章推荐
用libtemplate实现静态网页生成
Oct 09 PHP
php str_pad 函数使用详解
Jan 13 PHP
PHP chmod 函数与批量修改文件目录权限
May 10 PHP
php命令行使用方法和命令行参数说明
Apr 08 PHP
php检测文件编码的方法示例
Apr 25 PHP
php从memcache读取数据再批量写入mysql的方法
Dec 29 PHP
php简单的上传类分享
May 15 PHP
PHP+mysql+ajax轻量级聊天室实现方法详解
Oct 17 PHP
PHP基于Closure类创建匿名函数的方法详解
Aug 17 PHP
PHP常见数组排序方法小结
Aug 20 PHP
多个Laravel项目如何共用migrations详解
Sep 25 PHP
PHP实现一个轻量级容器的方法
Jan 28 PHP
解决laravel5中auth用户登录其他页面获取不到登录信息的问题
Oct 08 #PHP
对laravel的session获取与存取方法详解
Oct 08 #PHP
laravel-admin 管理平台获取当前登陆用户信息的例子
Oct 08 #PHP
laravel5.1框架model类查询的实现方法
Oct 08 #PHP
在laravel框架中使用model层的方法
Oct 08 #PHP
Laravel-添加后台模板AdminLte的实现方法
Oct 08 #PHP
PHP7.3.10编译安装教程
Oct 08 #PHP
You might like
漂亮但不安全的CTB
2006/10/09 PHP
php object转数组示例
2014/01/15 PHP
PHP整合PayPal支付
2015/06/11 PHP
phpMyAdmin通过密码漏洞留后门文件
2018/11/20 PHP
jquery使用remove()方法删除指定class子元素
2015/03/26 Javascript
JS实现可调整倒计时间代码分享
2015/08/18 Javascript
js修改onclick动作的四种方法(推荐)
2016/08/18 Javascript
微信小程序 navigation API实例详解
2016/10/02 Javascript
JS实现的适合做faq或menu滑动效果示例
2016/11/17 Javascript
JS区分Object与Aarry的六种方法总结
2017/02/27 Javascript
jQuery+CSS3实现点赞功能
2017/03/13 Javascript
jq源码解析之绑在$,jQuery上面的方法(实例讲解)
2017/10/13 jQuery
python中sets模块的用法实例
2014/09/30 Python
Python中使用dom模块生成XML文件示例
2015/04/05 Python
pandas获取groupby分组里最大值所在的行方法
2018/04/20 Python
tensorflow 加载部分变量的实例讲解
2018/07/27 Python
python3+opencv3识别图片中的物体并截取的方法
2018/12/05 Python
关于python中密码加盐的学习体会小结
2019/07/15 Python
详解pandas中MultiIndex和对象实际索引不一致问题
2019/07/23 Python
Python实现的爬取豆瓣电影信息功能案例
2019/09/15 Python
Python Opencv轮廓常用操作代码实例解析
2020/09/01 Python
手把手教你用Django执行原生SQL的方法
2021/02/18 Python
俄罗斯金苹果网上化妆品和香水商店:Goldapple
2019/12/01 全球购物
意大利时尚奢侈品店:D’Aniello Boutique
2021/01/19 全球购物
大学毕业生最详细的自我评价分享
2013/11/18 职场文书
个人自我评价分享
2013/12/20 职场文书
鲜花方阵解说词
2014/02/13 职场文书
文秘应聘自荐书范文
2014/02/18 职场文书
《画风》教学反思
2014/04/16 职场文书
小学阳光体育活动总结
2014/07/05 职场文书
教师党员学习十八届四中全会思想汇报
2014/11/03 职场文书
测量员岗位职责
2015/02/14 职场文书
2015年暑期实践报告范文
2015/07/13 职场文书
python实现图片九宫格分割的示例
2021/04/25 Python
AJAX学习笔记
2021/05/18 Javascript
解决 Redis 秒杀超卖场景的高并发
2022/04/12 Redis