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编程网上资源导航
Oct 09 PHP
建立文件交换功能的脚本(三)
Oct 09 PHP
深入php-fpm的两种进程管理模式详解
Jun 03 PHP
php中文乱码怎么办如何让浏览器自动识别utf-8
Jan 15 PHP
CodeIgniter输出中文乱码的两种解决办法
Jun 12 PHP
php表单敏感字符过滤类
Dec 08 PHP
基于PHP+jQuery+MySql实现红蓝(顶踩)投票代码
Aug 25 PHP
CI框架源码解读之利用Hook.php文件完成功能扩展的方法
May 18 PHP
PHP进阶学习之类的自动加载机制原理分析
Jun 18 PHP
使用swoole 定时器变更超时未支付订单状态的解决方案
Jul 24 PHP
PHP MVC框架中类的自动加载机制实例分析
Sep 18 PHP
PHP实现简单的协程任务调度demo示例
Feb 01 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生成扭曲及旋转的验证码图片
2013/06/07 PHP
php通过baihui网API实现读取word文档并展示
2015/06/22 PHP
Yii2使用自带的UploadedFile实现的文件上传
2016/06/20 PHP
PHP按符号截取字符串的指定部分的实现方法
2018/09/10 PHP
PHP生成随机码的思路与方法实例探索
2019/04/11 PHP
jquery中实现标签切换效果的代码
2011/03/01 Javascript
js控制表单操作的常用代码小结
2013/08/15 Javascript
javascript jq 弹出层实例
2013/08/25 Javascript
JS判断客服QQ号在线还是离线状态的方法
2015/01/13 Javascript
封装好的一个万能检测表单的方法
2015/01/21 Javascript
完美解决IE9浏览器出现的对象未定义问题
2016/09/29 Javascript
javascript实现用户点击数量统计
2016/12/25 Javascript
jQuery插件FusionCharts绘制的3D饼状图效果实例【附demo源码下载】
2017/03/03 Javascript
详解vue表单验证组件 v-verify-plugin
2017/04/19 Javascript
在 React、Vue项目中使用SVG的方法
2018/02/09 Javascript
vue 设置路由的登录权限的方法
2018/07/03 Javascript
简述vue状态管理模式之vuex
2018/08/29 Javascript
vuex如何重置所有state(可定制)
2019/01/17 Javascript
使用Vue.js中的过滤器实现幂方求值的方法
2019/08/27 Javascript
[40:19]完美世界DOTA2联赛PWL S3 Rebirth vs CPG 第二场 12.18
2020/12/19 DOTA
轻松实现TensorFlow微信跳一跳的AI
2018/01/05 Python
Python字符串格式化%s%d%f详解
2018/02/02 Python
在Django中URL正则表达式匹配的方法
2018/12/20 Python
详解Python静态网页爬取获取高清壁纸
2019/04/23 Python
深入了解python中元类的相关知识
2019/08/29 Python
django中使用事务及接入支付宝支付功能
2019/09/15 Python
python使用pip安装SciPy、SymPy、matplotlib教程
2019/11/20 Python
Python新手学习装饰器
2020/06/04 Python
CSS改变网页中鼠标选中文字背景颜色例子
2014/04/23 HTML / CSS
SmartBuyGlasses意大利:购买太阳镜、眼镜和隐形眼镜
2018/11/20 全球购物
英国健康和美容技术产品购物网站:CurrentBody
2019/07/17 全球购物
学院书画协会部门岗位职责
2013/12/01 职场文书
三月雷锋月活动总结
2014/07/03 职场文书
会计求职自荐信范文
2015/03/04 职场文书
死亡诗社观后感
2015/06/05 职场文书
2016习总书记系列重要讲话心得体会
2016/01/15 职场文书