Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Faker how to get min and max length for username

Tags:

laravel

faker

I want to get a min length of 1 and a max of 3.

I have tried $faker->username(1,3);

It's still producing usernames with higher lengths.

Also how can I make it to only have letters? Sometimes it has periods in the username.

<?php

use Faker\Generator as Faker;

$factory->define(App\User::class, function (Faker $faker) {
    return [
        'username' => $faker->username(1,3)
    ];
});
like image 930
larrarygizmal Avatar asked May 13 '18 14:05

larrarygizmal


1 Answers

you can try to use

$faker->realText(mt_rand(1, 3))
like image 144
ushi-deshi Avatar answered Nov 05 '22 19:11

ushi-deshi