Faker offers a couple of methods that let you replace placeholders in a given string with random characters:

  • lexify - takes given string and replaces ? with random letters
  • asciify - takes given string and replaces * with random ascii characters
  • numerify - takes given string and replaces # with random digits
  • bothify - combines the lexify and numerify

You could try to use one of them, depending on the requirements you have for that random string you need. asciify uses the largest set of characters as replacement so using that one makes most sense.

The following will give you a random string of 20 ascii characters:

$faker->asciify('********************')
Answer from jedrzej.kurylo on Stack Overflow
🌐
FakerPHP
fakerphp.org › formatters › numbers-and-strings
Numbers and Strings - FakerPHP / Faker
echo $faker->numerify(); // '912', '271', '109', '674' echo $faker->numerify('user-####'); // 'user-4928', 'user-3427', 'user-1280' Generate a string where all ? characters are replaces with a random letter from the Latin alphabet.
🌐
Laravel Daily
laraveldaily.com › post › generate-random-strings-laravel-helper-methods
Generate Random Strings with Laravel: Helper Methods
May 22, 2024 - Laravel have a fake() helper which resolves to a Faker package. With the help of a faker, you can generate various things. The asciify() or regexify() methods can be used to generate a random string using faker.
🌐
Shortcode
shortcode.dev › laravel › faker.html
Laravel cheatsheet > Faker
$faker = Faker\Factory::create(); $faker->name; // First and second name $faker->randomDigit; // A random number $faker->word; // A single word $faker->sentence; // A sentence $faker->unique()->word; // A single unique word $faker->text($maxNbChars = 300); // 300 character long text ...
Find elsewhere
🌐
GitHub
github.com › fzaninotto › Faker
GitHub - fzaninotto/Faker: Faker is a PHP library that generates fake data for you · GitHub
Even if this example shows a property access, each call to $faker->name yields a different (random) result.
Starred by 26.7K users
Forked by 3.6K users
Languages   PHP
🌐
FakerPHP
fakerphp.org › formatters › miscellaneous
Miscellaneous - FakerPHP / Faker
echo $faker->sha1(); // '20d1061c44ca4eef07e8d129c7000101b3e872af', '28cda1350140b3465ea8f65b933b1dad98ee5425' Generate a random SHA-256 hash string.
🌐
AlexHost
alexhost.com › home › faq › mastering realistic data generation in laravel with faker: a comprehensive guide
Mastering Realistic Data Generation in Laravel with Faker: A Comprehensive Guide
September 30, 2025 - This will fill your users table with 50 records of random user data, making it easy to test your application with realistic data. Faker allows for more complex data generation to match specific needs in your testing environment.
🌐
FakerPHP
fakerphp.org › formatters › text-and-paragraphs
Text and Paragraphs - FakerPHP / Faker
Generate a string containing random single word. echo $faker->word(); // 'molestiae', 'occaecati', 'distinctio'
🌐
YouTube
youtube.com › watch
Laravel: Get a Random String in 5+ Ways - YouTube
There are various helper methods in Laravel/PHP to generate random strings.Faker docs: https://fakerphp.github.io/- - - - -Support the channel by checking ou...
Published   July 1, 2024
🌐
Redotheweb
redotheweb.com › 2014 › 03 › 04 › faker-generates-real-text.html
Faker Now Generates Real Text - Redo The Web
March 4, 2014 - You may recognize a taste of Lewis Carroll in this text, and you would be right. Here is another random string of real text: <?php echo $faker->realText(180); // you can specify a max number of characters
🌐
ZetCode
zetcode.com › php › faker
PHP Faker - generating fake data in PHP with Faker package
February 16, 2025 - The Faker allows to generate random digits, integers, or floating point values.
🌐
GitHub
github.com › fzaninotto › Faker › issues › 1215
Add random array generator · Issue #1215 · fzaninotto/Faker
May 17, 2017 - I have a test where a mock is supposed to return an array. I don't really care what's in that array because I just need to test that the tested method passes that array to another mock. Hence it'd be nice to have a random array generator in Faker.
Published   May 17, 2017
Author   elnur
🌐
Medium
medium.com › @andipyk › laravel-seeders-understanding-the-difference-between-this-faker-sentence-and-this-faker-text-189057bd975d
Laravel Seeders: Understanding the Difference Between $this->faker->sentence and $this>faker->text | by andi | Medium
May 13, 2024 - The default output is around 200 characters, but like sentence, this can be adjusted by passing an integer that specifies the maximum number of characters desired. ... echo $this->faker->text(); // Generates a random block of text.
🌐
Laravel
laravel.com › docs › 7.x › database-testing
Database Testing | Laravel 7.x - The clean stack for Artisans and agents
Within the Closure, which serves as the factory definition, you may return the default test values of all attributes on the model. The Closure will receive an instance of the Faker PHP library, which allows you to conveniently generate various kinds of random data for testing.