简体   繁体   English

Laravel 假公寓号

[英]Laravel fake apartment number

I want to generate fake condo numbers, starting with a letter, a dash, and then a number我想生成假的公寓编号,以字母、破折号开头,然后是数字

The letter should be A, B, or C字母应为 A、B 或 C

The number after shouldn't go above 100 go后面的数字不应该超过100

Ex:前任:

A-23 A-23

C-76 C-76

B-8 B-8

TIA TIA

I think you can do something like this我想你可以做这样的事情

$faker      = Factory::create();
$faker->numerify($faker->randomElement(['A','B','C'])."-##");

here are the docs这是文档

  1. randomElement 随机元素
  2. numerify 数字化

Just use the regexify from faker只需使用来自 faker 的 regexify

example:例子:

$faker = Faker\Factory::create();
$faker->regexify('[A-C]{1}-[0-9]{2}');

the output gonna be something like this below: output 将如下所示:
// 'A-36', 'C-05', 'B-19' // 'A-36', 'C-05', 'B-19'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM