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 相关文章推荐
dedecms系统常用术语汇总
Apr 03 PHP
php SQL Injection with MySQL
Feb 27 PHP
php中取得URL的根域名的代码
Mar 23 PHP
PHP中将ip地址转成十进制数的两种实用方法
Aug 15 PHP
简单实用的.net DataTable导出Execl
Oct 28 PHP
PHP使用正则表达式清除超链接文本
Nov 12 PHP
php读取3389的脚本
May 06 PHP
PHP+memcache实现消息队列案例分享
May 21 PHP
php树型类实例
Dec 05 PHP
php实现中文字符截取防乱码方法汇总
Apr 29 PHP
php strftime函数的详细用法
Jun 21 PHP
PHP设计模式(五)适配器模式Adapter实例详解【结构型】
May 02 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/27 PHP
ThinkPHP CURD方法之limit方法详解
2014/06/18 PHP
PHP获取服务器端信息的方法
2014/11/28 PHP
php图片水印添加、压缩、剪切的封装类实现
2020/04/18 PHP
php实现简单的上传进度条
2015/11/17 PHP
php版微信自动获取收货地址api用法示例
2016/09/22 PHP
CodeIgniter整合Smarty的方法详解
2017/08/25 PHP
javascript multibox 全选
2009/03/22 Javascript
JavaScript类型转换方法及需要注意的问题小结(挺全面)
2010/11/11 Javascript
jQuery代码优化之基本事件
2011/11/01 Javascript
jquery 判断滚动条到达了底部和顶端的方法
2014/04/02 Javascript
javascript修改图片src的方法
2015/01/27 Javascript
利用JavaScript判断浏览器类型及版本
2016/08/23 Javascript
NodeJS远程代码执行
2016/08/28 NodeJs
node.js中grunt和gulp的区别详解
2017/07/17 Javascript
使用Vue-Router 2实现路由功能实例详解
2017/11/14 Javascript
Vue.js做select下拉列表的实例(ul-li标签仿select标签)
2018/03/02 Javascript
使用react context 实现vue插槽slot功能
2019/07/18 Javascript
刷新页面后让控制台的js代码继续执行
2019/09/20 Javascript
[57:22]完美世界DOTA2联赛PWL S2 FTD vs PXG 第二场 11.27
2020/12/01 DOTA
通过数据库对Django进行删除字段和删除模型的操作
2015/07/21 Python
日常整理python执行系统命令的常见方法(全)
2015/10/22 Python
Python实现选择排序
2017/06/04 Python
pandas创建新Dataframe并添加多行的实例
2018/04/08 Python
python实现xlwt xlrd 指定条件给excel行添加颜色
2020/07/14 Python
ffmpeg+Python实现B站MP4格式音频与视频的合并示例代码
2020/10/21 Python
Python读取ini配置文件传参的简单示例
2021/01/05 Python
Java的for语句中break, continue和return的区别
2013/12/19 面试题
汽车维修求职信
2014/06/15 职场文书
小学校园广播稿(3篇)
2014/09/19 职场文书
房屋买卖授权委托书
2014/09/27 职场文书
2016年重阳节慰问信
2015/12/01 职场文书
Python 把两层列表展开平铺成一层(5种实现方式)
2021/04/07 Python
python实现简单的名片管理系统
2021/04/26 Python
5人制售《绝地求生》游戏外挂获利500多万元 被判刑
2022/03/31 其他游戏
MySQL 数据 data 基本操作
2022/05/04 MySQL