laravel批量生成假数据的方法

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个假数据。

数据库结果记录:

其他可用的东东:

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

(0)

相关推荐

  • Laravel 批量更新多条数据的示例

    引言 最近在写任务中,碰到一个问题,需要批量更新多条数据,但是Laravel没有提供这样的方法,Google了一些方法,刚好借着任务来举例说明一下. 任务要求 任务是一个简单的清除未读通知的API,其实就是把通知表中符合user id 和 is read = 0 的行中的 is_read改为1(0代表未读,1代表已读). 方法1 我首先想到的是利用where()方法查出user id和is read符合条件的notices,然后利用foreach循环和save()更新数据表. $notices

  • Laravel中数据迁移与数据填充的详细步骤

    前言 这是一篇基础教程,对标 Laravel 文档中的数据迁移和数据填充,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍把. 关于Laravel数据库迁移的理解 最初看到laravel框架中迁移的时候,会以为这个迁移是把数据从一个数据库中迁到另一个数据库中,又或者是从一个服务器迁移到另一个服务器中.我自己学习有一个学习方法叫做顾名思义,所以所述是我的第一反应,但是学了以后发现这个迁移不是我理解中的迁移,但又不知道为什么叫做迁移,所以去百科查了一下. 迁移是指已经获得的知识.技能,甚

  • 使用laravel的migrate创建数据表的方法

    laravel中可以使用migration创建数据表,这使得数据库的迁移非常便利,下面介绍一下laravel中使用migration创建数据表的过程.数据库使用的是mysql,laravel版本为5.5 1. 创建并连接数据库 创建数据库 在命令行中输入mysql -u root -p然后输入数据库密码, 创建数据库create database work_space, 回车完成数据库的创建 连接数据库 打开项目中的.env文件 APP_NAME=Laravel APP_ENV=local AP

  • laravel批量生成假数据的方法

    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; #定义假数据长什么样子 retur

  • python用faker库批量生成假数据

    楔子 我们平时在做测试的时候,经常会使用一些假数据,而Python中有一个包叫faker(不是打LOL的那个),专门用来生成假数据,并且生成的假数据非常逼真,下面我们就来看一下. faker使用方法 基本使用 faker使用起来非常简单,我们看一下就知道了. from faker import Faker # 导入Faker这个类, 实例化即可 fake = Faker(locale="zh_CN") # 然后调用里面的方法即可生成相应的假数据 print(fake.name()) #

  • mybatis单笔批量保存实体数据的方法

    这一篇主要介绍,如何保存实体数据.具体内容如下所示: 一,xml样例 <?xml version="1.0" encoding="GBK"?> <!-- 1..1 --> <cisReports batNo="查询批次号" unitName="查询单位名称" subOrgan="分支机构名称" queryUserID="查询操作员登录名" queryCoun

  • mock.js实现模拟生成假数据功能示例

    本文实例讲述了mock.js实现模拟生成假数据功能.分享给大家供大家参考,具体如下: mock使用方法很简单, 下面是简单的用法, 详细的用法可以看官方文档, 写的很清楚, 下面的代码直接拷贝到本地html文件, 双击打开即可生成你想要的数据 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible"

  • python调用HEG工具批量处理MODIS数据的方法及注意事项

    下面的代码主要用于使用python语言调用NASA官方的MODIS处理工具HEG进行投影坐标转换与重采样批量处理 主要参考 HEG的用户手册:https://newsroom.gsfc.nasa.gov/sdptoolkit/HEG/HEG215/EED2-TP-030_Rev01_HEG_UsersGuide_2.15.pdf HEG批处理帮助:https://newsroom.gsfc.nasa.gov/sdptoolkit/HEG/HEG_Batch_job_Help.htm 主要的注意事

  • 使用python批量生成insert语句的方法

    1.建表语句 2.目标insert语句 INSERT INTO `bidprcu_dic_a`( `DIC_ID`, `DIC_TYPE_CODE`, `DIC_TYPE_NAME`, `DATA_DIC_CODE`, `DATA_DIC_NAME`, `PRNT_CODE`, `SRT`, `MEMO`, `DATA_SOUC`, `RID`, `CRTER_ID`, `CRTER_NAME`, `CRTE_OPTINS_NO`, `CRTE_TIME`, `OPT_TIME`, `OPTER

  • PHP生成plist数据的方法

    本文实例讲述了PHP生成plist数据的方法.分享给大家供大家参考.具体如下: 这段代码实现PHP数组转换为苹果plist XML或文本格式 <?PHP /** * PropertyList class * Implements writing Apple Property List (.plist) XML and text files from an array. * * @author Jesus A. Alvarez <zydeco@namedfork.net> */ funct

  • Python批量获取基金数据的方法步骤

    20年初准备投资基金,想爬取基金的业绩数据. 20年基金迎来了爆发式增长,现把代码开源以供参考. 本代码只能实现初步汇总,输出csv文件来保存基金的单位&累计净值,后期仍需要结合统计方法来筛选优质基金. 参考了网上的部分代码,实在不记得出处了,侵删. import requests import time import execjs start = time.perf_counter() # 获取所有基金编号 def getAllCode(): url = 'http://fund.eastmo

  • Python批量生成字幕图片的方法详解

    目录 说明 前提 放码 说明 视频剪辑时需要为视频添加字幕,添加字幕方法之一:根据字幕文本文件批量生成透明底只有字幕内容的图片文件,如下图,然后将这些图片文件添加到视频剪辑软件轨道中. 于是用pillow这Python图片工具库执行本次批量生成工作. 前提 pip intall pillow 放码 from PIL import Image, ImageDraw, ImageFont import os imageWidth, imageHeight = 1920, 1080 fontsFold

  • ASP页面静态化批量生成代码分享(多种方法)

    1.ASP两种简单的生成静态首页的方法 为什么要生成静态首页? 1.如果你首页读取的数据库次数比较多,速度很慢,而且占用很多服务器资源.使用静态页面访问速度当然快多了 2.搜索引擎容易搜索到 3.如果程序出问题,也能保证首页能访问. 4.其他的太多,自己想:) 应用方式: 如果你的首页是index.asp,你可以生成index.htm (默认访问顺序必须是index.htm,index.asp).这样访问者第一次访问到你的网站的时候打开的是index.htm .你可以把网站首页的链接做成inde

随机推荐