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 4.2书写安全的脚本
Oct 09 PHP
使用php来实现网络服务
Sep 15 PHP
php ss7.5的数据调用 (笔记)
Mar 08 PHP
PHP isset()与empty()的使用区别详解
Aug 29 PHP
php使用异或实现的加密解密实例
Sep 04 PHP
html静态页面调用php文件的方法
Nov 13 PHP
php生成随机颜色方法汇总
Dec 03 PHP
详解php的socket通信
Aug 11 PHP
php封装好的人民币数值转中文大写类
Dec 20 PHP
php版微信公众平台实现预约提交后发送email的方法
Sep 26 PHP
AJAX的使用方法详解
Apr 29 PHP
ThinkPHP框架下微信支付功能总结踩坑笔记
Apr 10 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
建立动态的WML站点(一)
2006/10/09 PHP
PHP操作数组的一些函数整理介绍
2011/07/17 PHP
PHP curl实现抓取302跳转后页面的示例
2014/07/04 PHP
一个简单安全的PHP验证码类 附调用方法
2016/06/24 PHP
laravel学习教程之关联模型
2016/07/30 PHP
Laravel监听数据库访问,打印SQL的例子
2019/10/24 PHP
通过JS 获取Mouse Position(鼠标坐标)的代码
2009/09/21 Javascript
从零开始学习jQuery (十) jQueryUI常用功能实战
2011/02/23 Javascript
纯文字版返回顶端的js代码
2013/08/01 Javascript
jQuery prev ~ siblings选择器使用介绍
2013/08/09 Javascript
Javscript调用iframe框架页面中函数的方法
2014/11/01 Javascript
jQuery横向擦除焦点图特效代码分享
2015/09/06 Javascript
js调用webservice构造SOAP进行身份验证
2016/04/27 Javascript
jQuery为DOM动态追加事件的方法
2017/02/16 Javascript
如何写好你的JavaScript【推荐】
2017/03/02 Javascript
jQuery事件对象的属性和方法详解
2017/09/09 jQuery
vue 虚拟dom的patch源码分析
2018/03/01 Javascript
vue实现element表格里表头信息提示功能(推荐)
2019/11/20 Javascript
vue如何实现动态加载脚本
2020/02/05 Javascript
JS Web Flex弹性盒子模型代码实例
2020/03/10 Javascript
python发送arp欺骗攻击代码分析
2014/01/16 Python
Python文档生成工具pydoc使用介绍
2015/06/02 Python
在Python中定义和使用抽象类的方法
2016/06/30 Python
详解安装mitmproxy以及遇到的坑和简单用法
2019/01/21 Python
Python 一行代码能实现丧心病狂的功能
2020/01/18 Python
Django限制API访问频率常用方法解析
2020/10/12 Python
python如何发送带有附件、正文为HTML的邮件
2021/02/27 Python
Jupyter安装拓展nbextensions及解决官网下载慢的问题
2021/03/03 Python
软件售后服务承诺书
2014/05/21 职场文书
英语教师求职信
2014/06/16 职场文书
2015年办公室文秘工作总结
2015/04/30 职场文书
2015年学校保卫部工作总结
2015/05/11 职场文书
2016新年感言
2015/08/03 职场文书
英语导游欢迎词
2015/09/30 职场文书
MYSQL 无法识别中文的永久解决方法
2021/06/03 MySQL
Ajax实现异步加载数据
2021/11/17 Javascript