laravel中faker的方法总结

2024-05-16 04:32
文章标签 总结 方法 laravel faker

本文主要是介绍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

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

这篇关于laravel中faker的方法总结的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/993884

相关文章

PHP轻松处理千万行数据的方法详解

《PHP轻松处理千万行数据的方法详解》说到处理大数据集,PHP通常不是第一个想到的语言,但如果你曾经需要处理数百万行数据而不让服务器崩溃或内存耗尽,你就会知道PHP用对了工具有多强大,下面小编就... 目录问题的本质php 中的数据流处理:为什么必不可少生成器:内存高效的迭代方式流量控制:避免系统过载一次性

python获取指定名字的程序的文件路径的两种方法

《python获取指定名字的程序的文件路径的两种方法》本文主要介绍了python获取指定名字的程序的文件路径的两种方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要... 最近在做项目,需要用到给定一个程序名字就可以自动获取到这个程序在Windows系统下的绝对路径,以下

JavaScript中的高级调试方法全攻略指南

《JavaScript中的高级调试方法全攻略指南》什么是高级JavaScript调试技巧,它比console.log有何优势,如何使用断点调试定位问题,通过本文,我们将深入解答这些问题,带您从理论到实... 目录观点与案例结合观点1观点2观点3观点4观点5高级调试技巧详解实战案例断点调试:定位变量错误性能分

Python中 try / except / else / finally 异常处理方法详解

《Python中try/except/else/finally异常处理方法详解》:本文主要介绍Python中try/except/else/finally异常处理方法的相关资料,涵... 目录1. 基本结构2. 各部分的作用tryexceptelsefinally3. 执行流程总结4. 常见用法(1)多个e

Python中logging模块用法示例总结

《Python中logging模块用法示例总结》在Python中logging模块是一个强大的日志记录工具,它允许用户将程序运行期间产生的日志信息输出到控制台或者写入到文件中,:本文主要介绍Pyt... 目录前言一. 基本使用1. 五种日志等级2.  设置报告等级3. 自定义格式4. C语言风格的格式化方法

JavaScript中比较两个数组是否有相同元素(交集)的三种常用方法

《JavaScript中比较两个数组是否有相同元素(交集)的三种常用方法》:本文主要介绍JavaScript中比较两个数组是否有相同元素(交集)的三种常用方法,每种方法结合实例代码给大家介绍的非常... 目录引言:为什么"相等"判断如此重要?方法1:使用some()+includes()(适合小数组)方法2

Spring 依赖注入与循环依赖总结

《Spring依赖注入与循环依赖总结》这篇文章给大家介绍Spring依赖注入与循环依赖总结篇,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录1. Spring 三级缓存解决循环依赖1. 创建UserService原始对象2. 将原始对象包装成工

504 Gateway Timeout网关超时的根源及完美解决方法

《504GatewayTimeout网关超时的根源及完美解决方法》在日常开发和运维过程中,504GatewayTimeout错误是常见的网络问题之一,尤其是在使用反向代理(如Nginx)或... 目录引言为什么会出现 504 错误?1. 探索 504 Gateway Timeout 错误的根源 1.1 后端

MySQL 表空却 ibd 文件过大的问题及解决方法

《MySQL表空却ibd文件过大的问题及解决方法》本文给大家介绍MySQL表空却ibd文件过大的问题及解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考... 目录一、问题背景:表空却 “吃满” 磁盘的怪事二、问题复现:一步步编程还原异常场景1. 准备测试源表与数据

python 线程池顺序执行的方法实现

《python线程池顺序执行的方法实现》在Python中,线程池默认是并发执行任务的,但若需要实现任务的顺序执行,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋... 目录方案一:强制单线程(伪顺序执行)方案二:按提交顺序获取结果方案三:任务间依赖控制方案四:队列顺序消