laravel中faker的方法总结

 

laravel faker用法总结

安装
composer require fzaninotto/faker
 

一、基础方法:

随机数:randomDigit             // 7
不为空随机数:randomDigitNotNull // 5
随机数:randomNumber($nbDigits = NULL, $strict = false) //
随机浮点数:randomFloat($nbMaxDecimals = NULL, $min = 0, $max = NULL) // 48.8932
区间内的随机数:numberBetween($min = 1000, $max = 9000) // 8567
随机字母:randomLetter // 'b'
// returns randomly ordered subsequence of a provided array
随机选取数组中的几个,返回也为数组:randomElements($array = array ('a','b','c'), $count = 1) // array('c')
随机选取数组中的一个:randomElement($array = array ('a','b','c')) // 'b'
打乱字符串:shuffle('hello, world') // 'rlo,h eoldlw'
打乱数组:shuffle(array(1, 2, 3)) // array(2, 1, 3)
随机插入数字:numerify('Hello ###') // 'Hello 609'
随机字母替换:lexify('Hello ???') // 'Hello wgt'
随机字母或者数字替换:bothify('Hello ##??') // 'Hello 42jz'
asci码随机替换:asciify('Hello ***') // 'Hello R6+'
正则匹配后生成:regexify('[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}'); // sm0@y8k96a.ej
 

二、 Lorem

单词:word                                             // 'aut'
单词组:words($nb = 3, $asText = false) // array('porro', 'sed', 'magni')
句子:sentence($nbWords = 6, $variableNbWords = true) // 'Sit vitae voluptas sint non voluptates.'
句子数组:sentences($nb = 3, $asText = false) // array('Optio quos qui illo error.', 'Laborum vero a officia id corporis.', 'Saepe provident esse hic eligendi.')
段落:paragraph($nbSentences = 3, $variableNbSentences = true) // 'Ut ab voluptas sed a nam. Sint autem inventore aut officia aut aut blanditiis. Ducimus eos odit amet et est ut eum.'
段落数组:paragraphs($nb = 3, $asText = false) // array('Quidem ut sunt et quidem est accusamus aut. Fuga est placeat rerum ut. Enim ex eveniet facere sunt.', 'Aut nam et eum architecto fugit repellendus illo. Qui ex esse veritatis.', 'Possimus omnis aut incidunt sunt. Asperiores incidunt iure sequi cum culpa rem. Rerum exercitationem est rem.')
文本内容:text($maxNbChars = 200) // 'Fuga totam reiciendis qui architecto fugiat nemo. Consequatur recusandae qui cupiditate eos quod.'

三、 Person

称谓: title($gender = null|'male'|'female')     // 'Ms.'
男士称谓:titleMale // 'Mr.'
女士称谓:titleFemale // 'Ms.'
前缀:suffix // 'Jr.'
名字:name($gender = null|'male'|'female') // 'Dr. Zane Stroman'
名:firstName($gender = null|'male'|'female') // 'Maynard'
男士名:firstNameMale // 'Maynard'
女士名:firstNameFemale // 'Rachel'
字:lastName // 'Zulauf'
 

四、 Address

城市前缀:cityPrefix                          // 'Lake'
详细地址:secondaryAddress // 'Suite 961'
州:state // 'NewMexico'
州的缩写:stateAbbr // 'OH'
城市后缀:citySuffix // 'borough'
接到前缀:streetSuffix // 'Keys'
建筑物的号码:buildingNumber // '484'
城市:city // 'West Judge'
街道名称:streetName // 'Keegan Trail'
街道地址:streetAddress // '439 Karley Loaf Suite 897'
邮政编号:postcode // '17916'
详细地址:address // '8888 Cummings Vista Apt. 101, Susanbury, NY 95473'
国家:country // 'Falkland Islands (Malvinas)'
纬度:latitude($min = -90, $max = 90) // 77.147489
经度:longitude($min = -180, $max = 180) // 86.211205
 

五、 PhoneNumber

电话号码:phoneNumber             // '201-886-0269 x3767'
免费电话号码:tollFreePhoneNumber // '(888) 937-7238'
E164电话号码:e164PhoneNumber // '+27113456789'
 

六、 Company

短语:catchPhrase             // 'Monitored regional contingency'
结构:bs // 'e-enable robust architectures'
公司:company // 'Bogan-Treutel'
公司前缀:companySuffix // 'and Sons'
工作名称:jobTitle // 'Cashier'
 

七、Text

文本内容:realText($maxNbChars = 200, $indexSize = 2) // "And yet I wish you could manage it?) 'And what are they made of?' Alice asked in a shrill, passionate voice. 'Would YOU like cats if you were never even spoke to Time!' 'Perhaps not,' Alice replied."
 

八、DateTime(时间这块应该都能看懂的,就不翻译了)

unixTime($max = 'now')                // 58781813
dateTime($max = 'now', $timezone = null) // DateTime('2008-04-25 08:37:17', 'UTC')
dateTimeAD($max = 'now', $timezone = null) // DateTime('1800-04-29 20:38:49', 'Europe/Paris')
iso8601($max = 'now') // '1978-12-09T10:10:29+0000'
date($format = 'Y-m-d', $max = 'now') // '1979-06-09'
time($format = 'H:i:s', $max = 'now') // '20:49:42'
dateTimeBetween($startDate = '-30 years', $endDate = 'now', $timezone = null) // DateTime('2003-03-15 02:00:49', 'Africa/Lagos')
dateTimeInInterval($startDate = '-30 years', $interval = '+ 5 days', $timezone = null) // DateTime('2003-03-15 02:00:49', 'Antartica/Vostok')
dateTimeThisCentury($max = 'now', $timezone = null) // DateTime('1915-05-30 19:28:21', 'UTC')
dateTimeThisDecade($max = 'now', $timezone = null) // DateTime('2007-05-29 22:30:48', 'Europe/Paris')
dateTimeThisYear($max = 'now', $timezone = null) // DateTime('2011-02-27 20:52:14', 'Africa/Lagos')
dateTimeThisMonth($max = 'now', $timezone = null) // DateTime('2011-10-23 13:46:23', 'Antarctica/Vostok')
amPm($max = 'now') // 'pm'
dayOfMonth($max = 'now') // '04'
dayOfWeek($max = 'now') // 'Friday'
month($max = 'now') // '06'
monthName($max = 'now') // 'January'
year($max = 'now') // '1993'
century // 'VI'
timezone // 'Europe/Paris'
 

九、 Internet

邮箱:email                   // 'tkshlerin@collins.com'
安全邮箱:safeEmail // 'king.alford@example.org'
免费邮箱:freeEmail // 'bradley72@gmail.com'
公司邮箱:companyEmail // 'russel.durward@mcdermott.org'
免费邮箱域名:freeEmailDomain // 'yahoo.com'
安全邮箱域名:safeEmailDomain // 'example.org'
用户名:userName // 'wade55'
密码:password // 'k&|X+a45*2['
域名:domainName // 'wolffdeckow.net'
域名名称:domainWord // 'feeney'
tld // 'biz'
连接地址:url // 'http://www.skilesdonnelly.biz/aut-accusantium-ut-architecto-sit-et.html'
口号:slug // 'aut-repellat-commodi-vel-itaque-nihil-id-saepe-nostrum'
iPv4地址:ipv4 // '109.133.32.252'
本地的ipv4地址:localIpv4 // '10.242.58.8'
ipv6地址:ipv6 // '8e65:933d:22ee:a232:f1c1:2741:1f10:117c'
MAC地址:macAddress // '43:85:B7:08:10:CA'
 

十、UserAgent

用户代理:userAgent              // 'Mozilla/5.0 (Windows CE) AppleWebKit/5350 (KHTML, like Gecko) Chrome/13.0.888.0 Safari/5350'
谷歌:chrome // 'Mozilla/5.0 (Macintosh; PPC Mac OS X 10_6_5) AppleWebKit/5312 (KHTML, like Gecko) Chrome/14.0.894.0 Safari/5312'
火狐:firefox // 'Mozilla/5.0 (X11; Linuxi686; rv:7.0) Gecko/20101231 Firefox/3.6'
safari:safari // 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_7_1 rv:3.0; en-US) AppleWebKit/534.11.3 (KHTML, like Gecko) Version/4.0 Safari/534.11.3'
opera:opera // 'Opera/8.25
 
  • 1
  • 2
  • 3
  • 4
  • 5

github地址:

https://github.com/fzaninotto/Faker#installation

发布了72 篇原创文章 · 获赞 7 · 访问量 4万+

faker使用的更多相关文章

  1. laravle faker

    1.编辑 /database/factories/ModelFactory,添加新的类模型填充 $factory->define(App\Post::class, function (Faker ...

  2. php库Faker

    Faker License : MIT Source Code Allo点评:Faker是一个很神奇的项目,会自动生成拟真的数据,包括用户资料.长文本.IP.日期等等,在网站上线前测试时非常好用. g ...

  3. 使用faker 生成中文测试数据

    https://github.com/fzaninotto/Faker/blob/master/src/Faker/Provider/zh_CN/Address.php 常用的类型都在里面. 下面是一 ...

  4. python之造测试数据-faker(转载)

    在软件需求.开发.测试过程中,有时候需要使用一些测试数据,针对这种情况,我们一般要么使用已有的系统数据,要么需要手动制造一些数据. 在手动制造数据的过程中,可能需要花费大量精力和工作量,现在好了,有一 ...

  5. 5、faker.js数据模拟

    转载于:https://segmentfault.com/a/1190000008574028 今天发现了一个神器--json-server!在他的帮助下可以在很短的时间内搭建一个Rest API, ...

  6. Python的伪造数据生成器:Faker

    我们在开发中常常需要利用一些假数据来做测试,这种时候就可以使用 Faker 来伪造数据从而用来测试. Faker 是一个可以让你生成伪造数据的Python包.当你需要初始化数据库,创建美观的XML文档 ...

  7. Flask实战-留言板-使用Faker生成虚拟数据

    使用Faker生成虚拟数据 创建虚拟数据是编写Web程序时的常见需求.在简单的场景下,我们可以手动创建一些虚拟数据,但更方便的选择是使用第三方库实现.流行的python虚拟数据生成工具有Mimesis ...

  8. Python Faker的使用(1):基础使用方法与函数速查,生成随机数据

    在软件需求.开发.测试过程中,有时候需要使用一些测试数据,针对这种情况,我们一般要么使用已有的系统数据,要么需要手动制造一些数据. 在手动制造数据的过程中,可能需要花费大量精力和工作量,现在好了,有一 ...

  9. laravel Faker-1.faker假数据

    1. 安装 composer require fzaninotto/faker --dev 2. 创建 migrations 参考:laravel文档 3. 定义ModelFactory 说明: 默认 ...

  10. 使用faker去构造一个User-Agent

    faker可以仿造各种各样的信息,可以使用faker去构造一个User-Agent from faker import Factory f = Factory.create() 'User-Agent ...

随机推荐

  1. [LeetCode] 203. 移除链表元素(链表基本操作-删除)、876. 链表的中间结点(链表基本操作-找中间结点)

    题目 203. 移除链表元素 删除链表中等于给定值 val 的所有节点. 题解 删除结点:要注意虚拟头节点. 代码 class Solution { public ListNode removeEle ...

  2. [HDOJ1232]畅通工程(并查集)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1232 题目描述 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表, ...

  3. Linux实战(11):Centos后期添加网卡配置

    前言 最近在折腾网卡,发现在已装centos上的机器上直接加网卡,开机后在系统中是没有启动的,下面的步骤是启动的过程,大家可以参考一下. 正文 首先我们先看网卡配置目录下的文件跟网卡 查询UUID y ...

  4. vue项目初始化自定义webpack与eslint

    文章目录 问题 简化步骤 问题 // main.js import Antd from "ant-design-vue"; import "ant-design-vue/ ...

  5. netty学习心得2内存池

    http://frankfan915.iteye.com/blog/2199600 https://www.jianshu.com/p/13f72e0395c8:一个性能调优的文档,还有一些linux ...

  6. Pycharm永久激活2且jetbrains全系列产品

    Pycharm永久激活2 注意:本教程补丁来源于https://zhile.io,如有侵权请联系作者删除! 本项目只做学习研究之用,不得用于商业用途! 一.激活前注意事项 PyCharm尽量在官网下载 ...

  7. 搭建Linux服务器

    工欲善其事必先利其器, 虚拟机:百度云链接地址:https://pan.baidu.com/s/1_nWQh3WKF7xLs5-nmbZ8lA   (Vmware 12 ) Linux 7:百度云链接 ...

  8. Generator函数在流程控制中的应用

    扯蛋 做了两年的Nodejs全栈开发,不知道为什么跑来做游戏呢(大概是厦门nodejs不好找工作吧).用的是网易的pomelo的游戏框架.现接手了一个棋牌游戏:二十一点,不懂的规则的可以自行百度. 二 ...

  9. Redis小记(一)

    1.redis的数据结构 (1)动态字符串(SDS) redis自身构建了一个简单动态字符串的抽象类型,SDS,在redis里,包含字符串的键值对在底层都是由SDS来实现的. 除了用来保存数据库的字符 ...

  10. Hibernate4.3 继承映射

    一.单表继承映射 父子类合成一张表 An_id An_name gender Weight Height type 1 dog 1 300 D 2 cat 1 100 C 在Animal.hbm.xm ...