I'm looking for a way to generate random string between min and max number of characters using laravel Faker.
I have to create random strings between 4
and 20
characters.
This method str_random
will generate exactly 20 characters, but how to specify min number of characters?
<?php
use Faker\Generator as Faker;
$factory->define(App\User::class, function (Faker $faker) {
return [
'name' => str_random(20),
];
});
Updated: I'm using the following code now as a workaround:
'name' => substr($faker->name(), 0, rand(4, 20))
</div>