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 相关文章推荐
PHP的宝库目录--PEAR
Oct 09 PHP
如何使用动态共享对象的模式来安装PHP
Oct 09 PHP
PHP下常用正则表达式整理
Oct 26 PHP
php 伪造本地文件包含漏洞的代码
Nov 03 PHP
php环境无法上传文件的解决方法
Apr 30 PHP
PHP生成迅雷、快车、旋风等软件的下载链接代码实例
May 12 PHP
thinkphp区间查询、统计查询与SQL直接查询实例分析
Nov 24 PHP
php使用cookie保存用户登录的用户名实例
Jan 26 PHP
浅谈php中urlencode与rawurlencode的区别
Sep 05 PHP
PHP基于socket实现的简单客户端和服务端通讯功能示例
Jul 10 PHP
PHP explode()函数用法讲解
Feb 15 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
php读取数据库信息的几种方法
2008/05/24 PHP
php+mysql事务rollback&commit示例
2010/02/08 PHP
sae使用smarty模板的方法
2013/12/17 PHP
php简单统计字符串单词数量的方法
2015/06/19 PHP
图片轮换效果实现代码(点击按钮停止执行)
2013/04/12 Javascript
捕获和分析JavaScript Error的方法
2014/03/25 Javascript
分享两个手机访问pc网站自动跳转手机端网站代码
2020/12/24 Javascript
jQuery scrollFix滚动定位插件
2015/04/01 Javascript
jQuery实现鼠标悬停背景翻转的黑色导航菜单代码
2015/09/14 Javascript
Bootstrap轮播加上css3动画,炫酷到底!
2015/12/22 Javascript
Ajax和Comet技术总结
2017/02/19 Javascript
jQuery日程管理控件glDatePicker用法详解
2017/03/29 jQuery
判断div滑动到底部的scroll实例代码
2017/11/15 Javascript
layui框架中layer父子页面交互的方法分析
2017/11/15 Javascript
JS获取子节点、父节点和兄弟节点的方法实例总结
2018/07/06 Javascript
在小程序/mpvue中使用flyio发起网络请求的方法
2018/09/13 Javascript
详解webpack打包后如何调试的方法步骤
2018/11/07 Javascript
JavaScript实现的鼠标跟随特效示例【2则实例】
2018/12/22 Javascript
JavaScript设计模式之代理模式实例分析
2019/01/16 Javascript
js实现页面导航层级指示效果
2020/08/25 Javascript
[01:08:09]DOTA2上海特级锦标赛主赛事日 - 1 胜者组第一轮#1Liquid VS Alliance第二局
2016/03/02 DOTA
[01:05:30]VP vs TNC 2018国际邀请赛小组赛BO2 第一场 8.17
2018/08/20 DOTA
用python分割TXT文件成4K的TXT文件
2009/05/23 Python
python将xml xsl文件生成html文件存储示例讲解
2013/12/03 Python
Python实现返回数组中第i小元素的方法示例
2017/12/04 Python
Python判断字符串是否xx开始或结尾的示例
2019/08/08 Python
python-numpy-指数分布实例详解
2019/12/07 Python
python安装第三方库如xlrd的方法
2020/10/31 Python
美体小铺瑞典官方网站:The Body Shop瑞典
2018/01/27 全球购物
台湾东南旅游社网站:东南旅游
2019/02/11 全球购物
init进程的作用
2012/04/12 面试题
幼儿园的门卫岗位职责
2014/04/10 职场文书
初中数学教学反思范文
2016/02/17 职场文书
MySQL基础(一)
2021/04/05 MySQL
游戏开发中如何使用CocosCreator进行音效处理
2021/04/14 Javascript
Go 语言下基于Redis分布式锁的实现方式
2021/06/28 Golang