有什么方法可以使用 laravel faker 生成假字符串?
就像在 laravel 中我们生成最多 20 个字符的字符串..
str_random(20);
有什么方法可以使用 laravel faker 生成假字符串?
就像在 laravel 中我们生成最多 20 个字符的字符串..
str_random(20);
Faker 提供了几种方法,可以让你用随机字符替换给定字符串中的占位符:
您可以尝试使用其中之一,具体取决于您对所需随机字符串的要求。asciify使用最大的字符集作为替换,因此使用它最有意义。
以下将为您提供20 个 ASCII 字符的随机字符串:
$faker->asciify('********************')
替代生成没有特殊字符的字符串。
$faker->regexify('[A-Za-z0-9]{20}')
$faker->text($maxNbChars = 50);
使用 Faker \Provider\en_US\Text
<?php
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."
$faker->text()
// generates 50 char by default: "Aut quo omnis placeat eos omnis eos."
$faker->text(10);
// generates 10 char by default: "Labore."
所有文本似乎都是一个或多个带有空格的拉丁伪句子,并且(每个句子的)末尾总是一个点。