是否有任何方法或技巧可以使用 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->text()
// generates 50 char by default: "Aut quo omnis placeat eos omnis eos."
$faker->text(10);
// generates 10 char by default: "Labore."
uze 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."